大网数据广告活动
网站运营与故障问答

How to specify expiry to a (css/js) files of a website in a shared hosting?

· 52CE 我爱测

I have read the other answers but all are based on editing the .htaccess file. Is there any way to set expiry without touching the .htaccess file?

问题原文

原帖链接 · Mukhar Jain · CC BY-SA 3.0

I have read the other answers but all are based on editing the .htaccess file. Is there any way to set expiry without touching the .htaccess file?

已采纳解答

原帖链接 · Simon Hayter · CC BY-SA 3.0

Yes it is possible using Apache and PHP, by setting the expires and cache-control using header(), you can find out more about what is, and what is not supported in the HTTP/1.1 specification. PHP headers will look something like this:

$seconds_to_cache = 3600;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");

You can find more help in regards of setting up PHP headers on Stack Overflow, here's a just few to get you started:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。