Code Splitting
See original GitHub issueGWT has a cool feature named Code Splitting which loads parts of the code on demand. This is also appliable for webmake.
Here my idea:
// a.js:
var b = require("b");
// ...
bindEventHandlerForSomeRarEvent(function() {
// the magic keyword "process.nextTick", which behaves normally in node.js
// but so some special thing in webmake
process.nextTick(function(err) {
// Some code loading err handler
// err is undefined in node.js
if(err) { /* ... */ }
var c = require("c"); // really big libary, which is only needed in this rar case
// ...
});
});
webmake core would provide the magic process.nextTick function to the compiled code.
process.nextTick do this in the compiled code:
- store the callback function
- adds a script tag to the document
- the script contains JSONP
- callback function (JSONP) adds some new modules to the context
- and calls the stored callback function.
- in case of an error (ex. timeout) the stored callback function is called with some kind of error parameter
Here is a quick hint on the compiled files:
// output.js
( /* core code */
({
"a": function(/* ... */, process) {
// a.js:
var b = require("b");
// ...
bindEventHandlerForSomeRarEvent(function() {
// the magic keyword, which behaves normally in node.js
// but so some special thing in webmake
process.nextTick(function(err) {
// Some code loading err handler
// err is undefined in node.js
if(err) { /* ... */ }
var c = require("c"); // really big libary,
// which is only needed in this rar case
// ...
});
});
},
"b": function /* content of b.js */
// here is no "c": !!
// which saves bandwidth
// may be named "a.output.js":
webmake_magic_jsonp_function( // the jsonp callback function
"a", // origin of code loading (used for identifing the stored function)
{
"c": function(/* ... */, process) {
// the content of the big libary
},
"d": function(/* ... */, process) {
// d.js is here a dependency of c.js (optional)
}
}
This feature may makes the compile process a big complexer.
It may be useful for:
- loading parts of your webapp when accessing them
- loading polyfills only when necessary
- decrease startup time
Issue Analytics
- State:
- Created 12 years ago
- Reactions:56
- Comments:24 (8 by maintainers)
Top Results From Across the Web
Code-Splitting - React
Code -splitting your app can help you “lazy-load” just the things that are currently needed by the user, which can dramatically improve the...
Read more >Code Splitting - webpack
Code splitting is one of the most compelling features of webpack. This feature allows you to split your code into various bundles which...
Read more >Reduce JavaScript payloads with code splitting - web.dev
Code splitting is a technique that seeks to minimize startup time. When we ship less JavaScript at startup, we can get applications to...
Read more >What is Code Splitting? - How Next.js Works
Code -splitting is the process of splitting the application's bundle into smaller chunks required by each entry point. The goal is to improve...
Read more >All you need to know about JavaScript code splitting
Dynamic code splitting: Many of us 'statically' import JavaScript modules and dependencies so that they are bundled together into one file at ...
Read more >
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve moved it to https://github.com/webpack/webpack
Hope that is ok…
So that’s how it all started! https://twitter.com/TheNicoKoenig/status/941410877290491905