Considering caching in a browser extension and the stop/restarting of background service worker (or event page), which of the following would perform better?
- Importing One large-ish module with multiple classes
- Multiple smaller modules (4-5)
Most of the classes are used in service workers. Some of the classes are also used elsewhere as well (i.e. browser action popup an options page).
Multiple files provide a cleaner dependency structure. On the other hand, multiple file access may use more resources.
Example:
// background.js
import {one} from './one.js';
import {two} from './two.js';
import {three} from './three.js';
import {four} from './four.js';
// popup.js
import {one} from './one.js';
import {two} from './two.js';
// options.js
import {one} from './one.js';
import {four} from './four.js';
// ----- vs -----
// background.js
import {one, two, three, four} from './one.js';
// popup.js
import {one, two} from './one.js';
// options.js
import {one, four} from './one.js';