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

前端 未结 5 1115
遥遥无期
遥遥无期 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:49

    What I've done isn't lazy loading but I load some files before the others when my chrome extension icon is clicked. In my case, I wanted my util files before the others that utilize them:

    chrome.browserAction.onClicked.addListener(function() {
      chrome.tabs.executeScript(null, {file: "src/utils/utilFunction1.js"});
      chrome.tabs.executeScript(null, {file: "src/utils/utilFunction2.js"});
      chrome.tabs.executeScript(null, {file: "src/main.js"});
      chrome.tabs.executeScript(null, {file: "src/otherFeature.js"});
    });
    

提交回复
热议问题