控制无 cookie 域上的缓存
我的情况
我遵循雅虎 YSlow 的建议,我想将静态内容存储在子域上。但是,我想使用函数 filemtime()
来控制文件的缓存。
问题
问题是这个功能似乎不适用于子域。
我的问题
有没有办法实现我的两个目标?或者你对我有什么建议吗?任何解决方案或解决方法将受到高度赞赏。
更新
函数 filemtime()
现在正在子域上运行。我在输入路径时犯了一个错误。但它仍然不适用于其他领域。
错误如下:
警告:filemtime() [function.filemtime]:第 7 行 /mywebsite/public_html/index.php 中的 ../../otherdomain.com/file.css 统计失败
My situation
I am following the advice of Yahoo's YSlow and I would like to store my static content on a subdomain. However, I would like to use the function filemtime()
to control the cache of the files.
The problem
The problem is that this function doesn't seem to be working on subdomains.
My question
Is there a way to achieve both of my goals? Or do you have a suggestion for me? Any solution or workaround would be highly appreciated.
Update
The function filemtime()
is working on the subdomain now. I have made a mistake in typing the path. But it still ain't working on other domains.
The error is as follows:
Warning: filemtime() [function.filemtime]: stat failed for ../../otherdomain.com/file.css in /mywebsite/public_html/index.php on line 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能已为
domain.com
设置了cookie,因此它们将被传递到sub.domain.com
。您可以使用全新的域名,例如
cdndomain.com
吗?至于使用文件修改的缓存破坏器,请尝试这个...
然后确保 script.js 在未来发送过期标头(1 年就足够了)。
然后,当您更新此文件时,版本控制将会更改,从而破坏缓存并允许客户端下载新副本。
You may have set cookies for
domain.com
, so they will be passed tosub.domain.com
.Can you use a whole new domain, e.g.
cdndomain.com
?As for using a file modified cache buster, try this...
Then make sure
script.js
sends an expiry header way in the future (1 year is good enough).Then, when you update this file, the versioning will change, breaking the cache and allowing the client to download the new copy.
我通过在另一个域上创建一个 PHP 文件并向该文件发送请求以检查文件的修改时间来解决该问题。
I have solved the problem by creating a PHP file on the other domain and sending a request to this file to check the file's modification time.