用于javascript和css的PHP内容缓存

编程入门 行业动态 更新时间:2024-10-10 14:22:47
本文介绍了用于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文件扩展名,决定不缓存的东西。请参见 www.enhanceie/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 www.enhanceie/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内容缓存

本文发布于:2023-11-01 10:58:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549151.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   内容   javascript   css   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!