![]() Include this snippet in a regular script tag before using nomodule. ⚠️ There’s one caveat - Safari 10.1 & Mobile Safari 10.3 don’t understand nomodule, although it’s fixed for its next release. This lets modern browsers know to ignore this code - it will never even be fetched from the network. Once you’ve rolled up your ES6 and transpiled it to ES5, ship it as normal, but add the nomodule attribute. (Next, you’ll need to pass your code to Babel, Traceur, or Google’s Closure Compiler to do the remaining ES6 → ES5 compile steps- see Google for more - this is pretty well documented, but out of scope of this post). It does nothing with ES6 - ignoring await, async, etc. Rollup won’t transpile away new JavaScript features for very old, ES5-only browsers. Rollup ‘rolls up’ ES6 modules into a single file. Use tools to compile ES6 modules for legacy browsers This will also shorten your development cycle - you’ll literally not have to compile at all to test changes in any JavaScript, just reload and go. ![]() See the example - // or an inline script import įor browsers that support ES6 modules, you’re done. ![]() Modules must be eventually included in your HTML with type="module", which can appear as an inline or external script tag. The JavaScript community has developed impressive workarounds - read all about their history in a 2012 post by but there’s huge benefit in using the platform itself. Modules are an important part of building any web application which comprises more than trivial script. Chrome now joins many other modern browsers which also include support, some behind flags. ES6 modules are now supported in Chrome, from 61 onwards-they also work in older versions, but you’ll have to enable the Experimental Web Platform flag in chrome:flags.
0 Comments
Leave a Reply. |