将javascript和css内联在一个缩小的html文件以提高性能?

将javascript和css内联在一个缩小的html文件以提高性能?

问题描述:

典型的网站由一个index.html文件和一堆javascript和css文件组成。为了提高网站的性能,可以:

A typical website consists of one index.html file and a bunch of javascript and css files. To improve the performance of the website, one can:


  • 缩小javascript和css文件以减小文件大小。

  • 将javascript文件连接到一个文件,类似于css文件,以减少对服务器的请求数。对于常用的(和共享的)库(如jquery),将它们保留在外部是有意义的,允许浏览器缓存库并在不同的Web应用程序中重用它。

我想知道如果将连接的javascript和css文件内联到单个html文件中是有意义的,更多的请求数。这会提高您的网站的性能吗?

I'm wondering if it makes sense to put the concatenated javascript and css file inline in on single html file, which will reduce the number of requests even further. Will this improve the performance of your site? Or will it work reversed, making it impossible for the browser to cache anything?

将CSS和JS文件合并成一个文件将减少请求的数量,并使其加载速度更快。但是如所评论的,它将没有什么意义,除非你有一个页面的网站和该网页的加载时间是非常关键。所以你最好在我的意见中将CSS与Javascript分开。

Concatinating your CSS and JS files into one file will reduce the number of requests and make it load faster. But as commented, it won't make much sense unless you have a one-page site and the load time of that page is very critical. So you're better off to separate CSS from Javascript in my opinion.

这是一本书,您可以在其中了解更多有关该主题的信息:

Here's a book where you can learn more about the topic:

高性能网站