PHP包括(JavaScript和CSS文件)

时间:2022-11-05 20:50:58

If JavaScript and CSS files were included inside of pages it would cut down the number of http requests and therefore make the page load faster. I feel like I am missing something because it seems like any organization interested in lightning-quick pages would do this. However, I don't recall any sites having tons of CSS and JavaScript into their pages as I look at the source code.

如果JavaScript和CSS文件包含在页面内,它将减少http请求的数量,从而加快页面加载速度。我觉得我错过了一些东西,因为似乎任何对闪电般快速页面感兴趣的组织都会这样做。但是,当我查看源代码时,我不记得有任何网站有大量的CSS和JavaScript。

Questions:
What errors are in my statements above?
What are the drawbacks of this approach (shown in the title via psuedocde)?

问题:上述陈述中有哪些错误?这种方法的缺点是什么(通过psuedocde标题显示)?

3 个解决方案

#1


4  

If the data is in an external file it can be cached and reused on other pages (or the same page, revisited) without having to fetch it over the network again.

如果数据位于外部文件中,则可以将其缓存并重新用于其他页面(或同一页面,重新访问),而无需再次通过网络获取数据。

You get a minor performance penalty on the first page in exchange for a major performance enhancement on subsequent pages.

您在第一页上获得较小的性能损失,以换取后续页面上的主要性能增强。

#2


0  

Modularity is a major concern:

模块化是一个主要问题:

I can pick and choose which javascript and css files I want per page: otherwise I'd have a ton of css and javascript files that have all the different configurations (which is just messy).

我可以选择我想要的每页javascript和css文件:否则我会有大量的css和javascript文件具有所有不同的配置(这只是凌乱)。

I can also cache a file and hand it to someone else faster

我也可以缓存一个文件并更快地将其交给其他人

Where you will find an example of this happening is when sites chuck their images together into one png file and then use css to slice up the bits they want for buttons etc.

你会发现这种情况的一个例子是当网站将他们的图像放在一个png文件中,然后使用css切片他们想要的按钮等。

#3


0  

Another aspect not only for inline css and jscript. When I write code I hate to repeat. It leads to errors is difficult to maintain (update/edit) and a waste of time and space. Printing CSS or jscript once in a file that gets downloaded once is less error prone, easy to maintain and less waste of time and space.

另一个方面不仅是内联css和jscript。当我编写代码时,我讨厌重复。它导致错误难以维护(更新/编辑)并浪费时间和空间。在一次下载的文件中打印一次CSS或jscript不易出错,易于维护,浪费时间和空间。

#1


4  

If the data is in an external file it can be cached and reused on other pages (or the same page, revisited) without having to fetch it over the network again.

如果数据位于外部文件中,则可以将其缓存并重新用于其他页面(或同一页面,重新访问),而无需再次通过网络获取数据。

You get a minor performance penalty on the first page in exchange for a major performance enhancement on subsequent pages.

您在第一页上获得较小的性能损失,以换取后续页面上的主要性能增强。

#2


0  

Modularity is a major concern:

模块化是一个主要问题:

I can pick and choose which javascript and css files I want per page: otherwise I'd have a ton of css and javascript files that have all the different configurations (which is just messy).

我可以选择我想要的每页javascript和css文件:否则我会有大量的css和javascript文件具有所有不同的配置(这只是凌乱)。

I can also cache a file and hand it to someone else faster

我也可以缓存一个文件并更快地将其交给其他人

Where you will find an example of this happening is when sites chuck their images together into one png file and then use css to slice up the bits they want for buttons etc.

你会发现这种情况的一个例子是当网站将他们的图像放在一个png文件中,然后使用css切片他们想要的按钮等。

#3


0  

Another aspect not only for inline css and jscript. When I write code I hate to repeat. It leads to errors is difficult to maintain (update/edit) and a waste of time and space. Printing CSS or jscript once in a file that gets downloaded once is less error prone, easy to maintain and less waste of time and space.

另一个方面不仅是内联css和jscript。当我编写代码时,我讨厌重复。它导致错误难以维护(更新/编辑)并浪费时间和空间。在一次下载的文件中打印一次CSS或jscript不易出错,易于维护,浪费时间和空间。