上面代码在网页中插入一个模块`foo.js"> 上面代码在网页中插入一个模块`foo.js"> \n\n上面代码在网页中插入一个模块`foo.js", "image": "https://self-blog-claude.oss-cn-hangzhou.aliyuncs.com/images/logo.jpg", "url": "https://www.cheert.com/static/176.html", "datePublished": "2020-10-14T08:21:20+08:00", "author": { "@type": "Person", "name": "Mickey", "url": "https://www.cheert.com" }, "publisher": { "@type": "Person", "name": "Mickey", "url": "https://www.cheert.com" }, "keywords": "" }

Mickey's Blog ·

ES6 module -浏览器的模块加载

浏览器使用 ES6 模块的语法如下。

<script type="module" src="foo.js"></script>

上面代码在网页中插入一个模块foo.js,由于type属性设为module,所以浏览器知道这是一个 ES6 模块。

浏览器对于带有type="module"<script>,都是异步加载外部脚本,不会造成堵塞浏览器。

对于外部的模块脚本(上例是foo.js),有几点需要注意。