用于javascript和css的PHP内容缓存 [英] PHP content caching for javascript and css

查看:168
本文介绍了用于javascript和css的PHP内容缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个独特的问题,这证明很难解决使用google。我把我所有的javascript和css合并到单独的php文件,它使用require_once()来拉取文件的内容。这个javascript文件看起来像这样:

 <?php 
header('Content-Type:text / javascript');
require_once('jquery.form.js');
require_once('jquery.jqtransform.js');
require_once('jquery.validate.js');
?>

我的具体问题是Web浏览器会看到这是一个动态页面,因为php文件扩展名,然后在每次加载网站上的网页时重新请求内容。我想要做的是获取浏览器的最后一次请求的时间,然后检查每个文件修改时间,看看我真的需要发送文件内容再次。证明难以找到用户的最后请求的时间。此外,我还没有开始解决找到包含的文件的最后修改日期的问题,因此如果有关于在服务器上找到文件的文件详细信息的信息,也要感谢。



为了清楚,我这样做的原因是因为(我认为)它利用了gzip压缩比单独gzip压缩文件更好。 / p>

提前感谢

解决方案

您的前提不正确。浏览器不看到PHP文件扩展名,决定不缓存的东西。请参见 http://www.enhanceie.com/redir/?id=httpperf



您应该在响应中设置ETAG,然后您可以简单地检查If-None-Match请求头并返回304如果内容不变。


I have a unique problem, which is proving difficult to solve using google. I am consolidating all of my javascript and css into separate php files, which use require_once() to pull the contents of the files in. The javascript file looks something like this:

<?php
header('Content-Type: text/javascript');
require_once('jquery.form.js');
require_once('jquery.jqtransform.js');
require_once('jquery.validate.js');
?>

My specific problem is that web browsers will 'see' that this is a dynamic page, because of the php file extension, and then request the content anew each time a page on the site is loaded. What I am trying to do is get the time of last request from the browser, and then check each file modification time to see if I really do need to send the file contents again. It is proving difficult to find the time of last request by the user. Also, I have not yet started to tackle the problem of finding the last modified date of the files that are included, so if there is information regarding finding the file details of a file on the server, that would also be appreciated.

Just to be clear, the reason I am doing this is because (I think) it takes advantage of the gzip compression better than individually gzipped files.

Thanks in advance

解决方案

Your premise is incorrect. Browsers don't "see" the PHP file extension and decide not to cache things. See http://www.enhanceie.com/redir/?id=httpperf for information on how browsers really work.

You should set an ETAG on your response, and then you can simply check the If-None-Match request header and return a 304 if the content is unchanged.

这篇关于用于javascript和css的PHP内容缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆