Plugin JS minification

I’m wondering what the official recommendation by the Obsidian team is about minifying the production main.js build of a plugin. I looked at my plugin folder and around half of them are not minified. I’m also writing my own plugin and want to follow best practices and be mindful of the users’ resources.

I also checked the official sample plugin repo and while tree-shaking is enabled, minify is not: obsidian-sample-plugin/esbuild.config.mjs at master · obsidianmd/obsidian-sample-plugin · GitHub

Does it make a practical difference when plugins are properly minified? Some of the aspects I’m thinking about:

  1. Initial plugin download time: it’s probably negligible and a one-time cost
  2. Sync: installed plugins don’t change often, and sync happens in the background anyway
  3. Plugin initialization time: I’m much more interested in this, especially on mobile. I know that the file is already on the disk, so bundle size doesn’t matter as much as on the web, but I’m still wondering if minification is making a difference here (or it’s just a micro-optimization?)
  4. Memory usage: I couldn’t find information about how a plugin is actually loaded into the app process. I guess once the code is parsed and evaluated, it doesn’t matter anymore if it’s aLongVariable or x, right? (Tree-shaking would be a different story, but I see that it’s enabled by default)
1 Like

Minification will improve the following things a bit:

  1. plugin load time (smaller time, less to read and parse)
  2. memory usage, less memory is needed for the program, as files and symbols are shorter

But it has the downside of harder debugging, as symbol names are not preserved

A solution with minification is to set: minifySyntax and minifyWhitespace to true for prod, as it keeps symbol name.

1 Like