Reputation: 175
Using JavaScript ES6 modules requires specifying a mime type in html like:
<script src="./js/graphics.js" crossorigin type="module"></script>
This will only load if a CORS header is added as a message header, which can only be added by a server, depending on server settings.
Am I correct to assume that this means that it is impossible to have a webpage which will still work offline while using ES6 modules ? So designing an offline first app is impossible using ES6 modules ?
Upvotes: 1
Views: 493
Reputation: 2348
If you want to make a really offline-first app, is a good idea to make one bundle with all your ES6 modules. For example, you can choose Webpack as your module bundler.
After the compilation, you will receive one .js file which you can include in your page and do not think about CORS.
It's is also helpful if you want to reduce page loading time, because every time you use tag, the browser makes a request to the server, so using only one bundle will reduce requests.
Upvotes: 1