javascripthtmlrequirejsjspm

JSPM bundle vs requireJs confusion


I am new to jspm. I have requrieJs background.

Is it true that jspm while bundling compiles all dependencies into one big file ? like jquery, jquery-ui,bootstrap, databases to other 50 plguins used in project ?

If yes, then What is benefit ? would it not be much faster to fetch items when required like in requrieJs ?


Solution

  • By default jspm does not bundle your dependencies. Every dependency is imported on its own. So if you have three files, say main.js, smth.js and jquery.js, jspm will require them one by one as soon as System.import is called. For static dependencies (like ES6 modules), it happens before the code is executed. But you can also require additional modules at runtime.

    The idea behind is that bundling is not really required with HTTP/2. jspm knows the entire dependency tree and it can request all of the dependencies in parallel. Then all files will be delivered over the same network connection which should be pretty the same as if you were bundling them at the build time.

    But since HTTP/1 is still to common, jspm offers bundle & build CLI. But those command only put everything in one big file by default. The process is highly configurable. You can exclude certain dependencies such as jquery and put them in a separate bundle or even load jquery from CDN. See https://jspm.io/docs/production-workflows.html#creating-a-bundle for more info how exclude/include modules.