-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
3.8, 4.1, 4.3
-
MOODLE_38_STABLE, MOODLE_401_STABLE, MOODLE_403_STABLE
-
MDL-66107-master
-
-
6
-
Team Hedgehog 4.1 sprint 0.4B, Team Hedgehog 4.1 sprint 0 rev, Team Hedgehog 4.1 pre 1.1
I've done a bit of research, and I believe that bundling all compiled JS in first.js is a false economy with significant drawbacks. These drawback include:
- At the moment, the first time a page is loaded we load all AMD JS in Moodle.
- This currently accounts for approximately 900KB (2019), and growing (2.1MB uncompressed and 461kB over the wire in 2022).
- Transfer time is also high with my 2022 development machine taking a significant amount of time to transfer the wire localy (Lots of variation but I had values in ms of: 742, 132, 148, 849, 829. 1050).
- The TTFB is also high at about 80ms as we combine all of the various files and then echo them out at the end. This therefore also has an impact on memory as all of this content is stored in memory until it is echoed out (peak memory usage just before we finish compiling is about 1.3MB).
- If any single JS file has an issue then all JS on the site will fail.
All of this means negative things for scale, for user experience, reliability, for browser memory usage, and for debugging.
From what I can see, whilst the initial page load will require more files to be fetched, these will be fetched faster, and cached more efficiently. We will also be more reliable (JS errors not killing the page), and less browser memory.
Additional changes of note
Source maps
At present, the differences between production and development include:
- combo-load vs. individual load
- no sourcemap in prod vs. sourcemap in dev
As we are removing support for combo-loading, I feel it is also prudent to add the missing sourcemap support in production code.
This was not originally included due to a bug in Firefox which has been fixed for several years. This bug meant that we had to include the entire source content in the source map, rather than referencing the original file. In the case of the combo-loader, this meant a very large sourceContent in the single source map, and the sourcemap did not work in Firefox well as a result.
Now that this issue has been resolved in Firefox, we can remove the sourceContent from the sourcemap, and include it in production code.
Legacy define
In MDL-62497 we included some changes to help developers transition to using the new transpilation process. These features are no longer relevant and it is safe to remove them.
Summary
Each part of this change is well documented in the individual commit messages with explanation of the changes.
The key change here is to stop using a combo loader to serve all JS content in a single (very large) file, and serve individual modules on request.
The main concern with this change is a change from a larger over-the-wire file-size to lots of smaller individual requets made to the server.
In my local testing, it seems that these changes are beneficial in most situations – the main area of concern being slower connections where round-trip time is much higher as there are more individual connections. These concerns are offset by the massive reduction in transferred filesize as only the requested modules are now fetched.
- has a non-specific relationship to
-
MDL-71882 Grunt babel should replace names of modules
- Closed
- is blocked by
-
MDL-75936 Race condition in message_drawer helper
- Closed
-
MDL-62497 Add a new transpilation tool for ES6
- Closed
- will be (partly) resolved by
-
MDL-65837 AMD modules loaded by YUI on pageload lead to duplicate requirejs loads
- Open
- will help resolve
-
MDL-52751 Better support HTTP/2
- Closed
-
MDL-59557 requirejs: Stop serving JavaScript from disabled plugins
- Closed