Multiple JS files in Chrome Extension - how to load them?

前端 未结 5 1121
遥遥无期
遥遥无期 2021-02-01 16:15

I\'ve wrote a Chrome Extension. My background.js file is quite large, so I want to split it to smaller parts and load specified methods when required (some kind of lazy-loading)

5条回答
  •  情深已故
    2021-02-01 16:38

    You can also do this the extremely easy way that is described here: https://developer.chrome.com/extensions/background_pages#manifest

    {
      "name": "My extension",
      ...
      "background": {
        "scripts": [
          "lib/fileone.js",
          "lib/filetwo.js",
          "background.js"
        ]
      },
      ...
    }
    

    You won't be doing lazy loading, but it does allow you to break your code up into multiple files and specify the order in which they are loaded onto the background page.

提交回复
热议问题