Home  >  Article  >  Web Front-end  >  高性能web建站规则(外部js和css通常更好一些)_html/css_WEB-ITnose

高性能web建站规则(外部js和css通常更好一些)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 08:46:321240browse

对于js和css,通常的做法有两种,一种将js和css直接嵌入到页面中,称为内联,另外一种就是通过src和link进行外部导入,称为外置。那么,哪一种更好一些呢?通常情况下外置更好一些,为什么呢?

  1. 用户往往从首页打开以后,会继续跳转到其余页面。比如说,从csdn首页到博客,再到极客头条,那么,假如打开首页时,外部的js和css被缓存起来了,接下来的请求中,公用的js和css就不会再从服务器上获取,内联的方式是没有办法缓存的。
  2. 假如说你网站的用户有很大的比重只访问首页,那么内联就会减少http请求,相对的加载速度就会更快。
  3. 但从大部分网站的功能上看,用户访问多个后续页面的几率要大于只访问首页,所以外置的倾向就会大一些。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn