我有對JavaScript文件expires
頭這是由PHP產生的問題過期了nginx的與JavaScript文件(由PHP動態生成)
該網站有兩種類型的JavaScript文件。一部分是靜態JavaScript文件,另一部分是由PHP動態生成的。
的conf沒有Expires頭
這裏沒有expires
頭文件(所有文件返回HTTP 200
)加入到.js
文件
location/{
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /var/ini/nginx/fastcgi.conf;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME /var/www/index.php;
}
的conf與Expires頭
當.js
文件添加地點那麼所有動態生成的文件返回HTTP 404
location/{
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /var/ini/nginx/fastcgi.conf;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME /var/www/dyndev.dk/public/secure/index.php;
}
location ~ \.(js|css)$ {
expires 1y;
add_header Cache-Control "public";
}
如何使用expires
頭文件處理靜態和動態生成的.js
文件?
所有動態genereated JavaScript文件被命名爲*-php.js
文件結構
/var/www/public/index.php # All none-static file requests are pointed to index.php
/var/www/public/js/main.js # Static files
/var/www/js-dynamically_generated.php # This file is outside the public www, but is routed by PHP since the file doesn't exists inside the public /js
PHP路由
www.example.com/ -> index.php
www.example.com/js -> static content
www.example.com/js/dynamically_generated-php.js -> js-dynamically_generated.php
如果你用php創建js爲什麼你不用PHP函數添加標題? – Kiyan
已更新我的問題 – clarkk