- Aug 2018
-
developer.mozilla.org developer.mozilla.org
-
same privileged JavaScript APIs
It better to call it Extension API
-
-
developer.mozilla.org developer.mozilla.org
-
WebExtension APIs in the script, as long as you have requested the necessary permissions.
some web extensions require the use of permissions
-
-
developers.google.com developers.google.com
-
Split the code into routes and pages
Instead of having a single large bundle file for your whole website, you can have multiple bundles for each page. This improves the load time of your website as you can tag bundle files to the various webpage of your site instead of one initial big download of script file.
-
runtume
*typo
-
Webpack includes this runtime into the last generated chunk, which is vendor in our case
confusing line!!
-
In webpack terminology, separate files with the app code are called chunks
webpack chunk definition
-
With webpack, you do the same, but instead of a version number, you specify the file hash.
Webpack caching using [chunkhash] is just like creating version number for your script file. filename.[chunkhash].js [chunkhash] can be assumed to be version number which the browser uses to check if the file has changed or not, and according to it updates the file in its cache.
-
App dependencies tend to change less often than the actual app code
vendor scripts
-
-
developers.google.com developers.google.com
-
One reason for this is
why optimised bundled modules load time is much better than unbundled modules
-
providing a fallback to other browsers
For non module supporting browsers we can add another script tag with the nomodule attribute
-
module specifier
import * from "./abc.js"; This string inside the double quotes is called MODULE SPECIFIER. It is used to specify the location of the module relative to the current folder or the root folder depending on wether we used / or ./
-
async attribute,
Scripts with the async attribute are loaded(downloaded) from the server asynchronously. That means there is no order in which the script is going to be executed. It doesn't block the HTML parser Script is executed as soon as it is downloaded, does not wait for HTML parsing to finish.
-
Also, module scripts and their dependencies are fetched with CORS. This means that any cross-origin module scripts must be served with the proper headers, such as Access-Control-Allow-Origin: *. This is not true for classic scripts.
CORS - Cross Origin Resource Sharing
-
mjs
modules have .mjs extension Not really important We can use .js as well The type attribute in our script tag is enough RECOMMENDED : We should use .mjs extension because during development it makes it easier to diffrentiate
-
same goes for all the dependency modules
Even the dependencies modules are defer by default
-
Browsers that understand type="module" ignore scripts with a nomodule attribute.
Only the latest browsers are module-supporting. For these browsers you can use a script tag with a type attribute set to module.
-
possible
Sexy example below. Makes the concept of dynamic import crystal clear. Although one must know the concept of async await function.
-
With modules, it becomes possible to develop websites without using bundlers such as webpack, Rollup, or Parcel
Only when you have a small webapp
-