Make JavaScript and CSS External .
来源:互联网 发布:加工中心编程格式要领 编辑:程序博客网 时间:2024/05/17 08:13
Many of these performance rules deal with how external components are managed. However, before these considerations arise you should ask a more basic question: Should JavaScript and CSS be contained in external files, or inlined in the page itself?
Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.
The key factor, then, is the frequency with which external JavaScript and CSS components are cached relative to the number of HTML documents requested. This factor, although difficult to quantify, can be gauged using various metrics. If users on your site have multiple page views per session and many of your pages re-use the same scripts and stylesheets, there is a greater potential benefit from cached external files.
Many web sites fall in the middle of these metrics. For these sites, the best solution generally is to deploy the JavaScript and CSS as external files. The only exception where inlining is preferable is with home pages, such as Yahoo!'s front page and My Yahoo!. Home pages that have few (perhaps only one) page view per session may find that inlining JavaScript and CSS results in faster end-user response times.
For front pages that are typically the first of many page views, there are techniques that leverage the reduction of HTTP requests that inlining provides, as well as the caching benefits achieved through using external files. One such technique is to inline JavaScript and CSS in the front page, but dynamically download the external files after the page has finished loading. Subsequent pages would reference the external files that should already be in the browser's cache.
Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.
The key factor, then, is the frequency with which external JavaScript and CSS components are cached relative to the number of HTML documents requested. This factor, although difficult to quantify, can be gauged using various metrics. If users on your site have multiple page views per session and many of your pages re-use the same scripts and stylesheets, there is a greater potential benefit from cached external files.
Many web sites fall in the middle of these metrics. For these sites, the best solution generally is to deploy the JavaScript and CSS as external files. The only exception where inlining is preferable is with home pages, such as Yahoo!'s front page and My Yahoo!. Home pages that have few (perhaps only one) page view per session may find that inlining JavaScript and CSS results in faster end-user response times.
For front pages that are typically the first of many page views, there are techniques that leverage the reduction of HTTP requests that inlining provides, as well as the caching benefits achieved through using external files. One such technique is to inline JavaScript and CSS in the front page, but dynamically download the external files after the page has finished loading. Subsequent pages would reference the external files that should already be in the browser's cache.
- Make JavaScript and CSS External .
- External JavaScript and PHP
- Make your pages load faster by combining and compressing javascript and css files
- Minify JavaScript and CSS .
- JavaScript and CSS
- iOS: load external image and css to UIWebView
- Dynamically loading an external JavaScript or CSS file
- use javascript make game1(rock, paper and scissors)
- External Javascript not working
- Inline vs. External Javascript
- css style and Javascript imitate WinXp
- Howto Dynamically Insert Javascript And CSS
- compressoer the javascript and Css code
- 3.1. 外部引用CSS -- External
- window.external的使用(javaScript)
- make a website ----css
- GNU make and Makefile
- make and makefile
- 文本框输入字母检索汉字
- Asp.Net MVC 3.0【MVC实战项目の二】
- JDBC连接各种数据库方法
- ping
- NSUserDefaults简介及使用
- Make JavaScript and CSS External .
- Asp.Net Mvc 3.0【MVC项目实战の三】
- DSP学习总结
- 指针&引用在C C++ JAVA 语言特性导致表达能力的差异
- 预处理指令作用
- Javascript调用后台方法
- python集锦(四)
- Remove Duplicate Scripts .
- Android给自定义控件添加自定义属性