如何在静态 PHP 生成的 CSS / JS 文件上取消设置 Cookie?
测试我的网站时,我看到 Cookie 得分为 81/100
,并带有以下评论:
FAILED(带有 1 个 cookie - 36 字节的静态对象)
- all.css cookie:PHPSESSID=3ge12i80ghj5gbb2cs41tr7qj5失败(带有 1 个 cookie 的静态对象 - 36 字节)
- all.js cookie:PHPSESSID=3ge12i80ghj5gbb2cs41tr7qj5出站 cookie 总计 0.2 KB - 潜在节省 = 0.2 KB
这两个文件实际上都是 PHP 生成的文件,它将许多其他 css / js 文件合并为一个。
我应该如何取消这些统计对象的 cookie?
是否有可以在 headers();
旁边添加的 php 代码来取消设置这些文件上的 cookie?
建议=答案=非常感谢!
Testing my site I saw a Cookie score of 81/100
with following comment:
FAILED (Static object with 1 cookies - 36 bytes)
- all.css
cookie:PHPSESSID=3ge12i80ghj5gbb2cs41tr7qj5FAILED (Static object with 1 cookies - 36 bytes)
- all.js
cookie:PHPSESSID=3ge12i80ghj5gbb2cs41tr7qj50.2 KB total in outbound cookies - potential savings = 0.2 KB
Both files are actually PHP generated files, that combine many other css / js files into one.
What should I do unset the cookie for these statis objects?
Is there a php code that I can add next to the headers();
that can unset the cookie on those files?
Suggestions = answers = Much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在这些脚本中的某个位置调用
session_start
。如果删除它,会话 cookie 将不会被设置。
It looks like you are calling
session_start
somewhere in those scripts.If you remove that, the session cookie will not be set.
PHPSESSID 将由浏览器随每个请求发送到您当前的域。请求什么文件类型(.html、.php、.js、.css 等)并不重要。看到这一点的一个好方法是使用 Firefox 的“Live HTTP Headers”插件。您可以准确地看到每个请求发送的内容。
为了防止发送 PHPSESSID,您可以从不同的域或可能的子域提供这些文件。理想的解决方案是使用 CDN。但是,我不担心浏览器发送这些文件的 PHPSESSID。
只是出于好奇,您使用什么工具来测试您的网站?
The PHPSESSID is going to be sent by the browser with every request to your current domain. It doesn't matter what file type is being requested (.html, .php, .js, .css, etc.). A good way to see this is using the "Live HTTP Headers" add-on for Firefox. You can see exactly what is being send with each request.
To prevent the PHPSESSID from being sent, you can serve these files from a different domain or possibly a sub-domain. The ideal solution is to use a CDN. However, I would not worry about the browser sending the PHPSESSID for these files.
Just out of curiosity, what tool are you using to test your site?