JS外链
2016-01-27 16:15
323 查看
<script type=”text/javascript” src=”example.js”></script>
外链的javascript都有一个.js的后缀,但是这并不是必须的,浏览器不会去检查后缀
它的意义是让后台的脚本可以动态的生成js代码
但是注意虽然服务器会通过文件拓展名来决定用那种mime类型给请求
但如果你没有写.js的,确保你的服务器返回正确的mime类型
另外外链js可以来自不同的外部域,编译器不会进行区分
如果添加defer属性,就不会推迟编译,不中断浏览器加载Dom,意思就是告诉浏览器,这个外链脚本不会改变dom结构,可以等整个页面编译完成之后再执行(也就是编译完</HTML>),在load事件之前。但是不确定在domcontentloaded事件前后,在html5的定义中,它们会按顺序执行
Async属性也会让浏览器立刻下载该文件,但是他们不是按前后顺序一个个执行,并没有明确的执行顺序。这样的目的是为了告诉浏览器不需要等待这个脚本完全下载完执行完才继续加载页面。也是在load事件之前执行
额外好处:
➤ Maintainability — JavaScript code that is sprinkled throughout various HTML pages turns code maintenance into a problem. It is much easier to have a directory for all JavaScript files so that developers can edit JavaScript code independent of the markup in which it’s used.
➤ Caching — Browsers cache all externally linked JavaScript files according to specific settings, meaning that if two pages are using the same file, the file is downloaded only once. This ultimately means faster page-load times.
➤ Future-proof — By including JavaScript using external files, there’s no need to use the XHTML or comment hacks mentioned previously. The syntax to include external files is the same for both HTML and XHTML.
外链的javascript都有一个.js的后缀,但是这并不是必须的,浏览器不会去检查后缀
它的意义是让后台的脚本可以动态的生成js代码
但是注意虽然服务器会通过文件拓展名来决定用那种mime类型给请求
但如果你没有写.js的,确保你的服务器返回正确的mime类型
另外外链js可以来自不同的外部域,编译器不会进行区分
如果添加defer属性,就不会推迟编译,不中断浏览器加载Dom,意思就是告诉浏览器,这个外链脚本不会改变dom结构,可以等整个页面编译完成之后再执行(也就是编译完</HTML>),在load事件之前。但是不确定在domcontentloaded事件前后,在html5的定义中,它们会按顺序执行
Async属性也会让浏览器立刻下载该文件,但是他们不是按前后顺序一个个执行,并没有明确的执行顺序。这样的目的是为了告诉浏览器不需要等待这个脚本完全下载完执行完才继续加载页面。也是在load事件之前执行
额外好处:
➤ Maintainability — JavaScript code that is sprinkled throughout various HTML pages turns code maintenance into a problem. It is much easier to have a directory for all JavaScript files so that developers can edit JavaScript code independent of the markup in which it’s used.
➤ Caching — Browsers cache all externally linked JavaScript files according to specific settings, meaning that if two pages are using the same file, the file is downloaded only once. This ultimately means faster page-load times.
➤ Future-proof — By including JavaScript using external files, there’s no need to use the XHTML or comment hacks mentioned previously. The syntax to include external files is the same for both HTML and XHTML.
相关文章推荐
- Struct2 或SSH项目中Action返回JSON数据该如何编辑
- json
- 省市县插件PCASClass.js的基本使用方法
- 通过js动态为标签元素添加点击事件
- html里js的execCommand的一点用法
- 原生js开发的弹框组件
- JavaScript复习笔记——字符串
- Javascript变量和属性的区别
- Struct2或者SSH项目中添加手机短信登录及期间遇到的一些问题
- ExtJS5 - 用鼠标拖拽Grid行进行排序及选择
- js中table的值进行点击排序
- JS 学习1--开始
- 使用javascript实现银行卡号的Luhn校验或验证算法
- Javascript性能优化之异步加载和执行
- 20160127--Jsp
- Extjs4 获取到前一天的日期
- JavaScript-时间倒计时
- JSP EL表达式详细介绍
- javascript改变position值实现菜单滚动至顶部后固定
- js checkbox