我正在尝试对我的静态文件使用缓存控制。下面是我对.htaccess文件的代码
# 1 YEAR
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>我使用Django-管道压缩我的JS和CSS文件。以下是我的相关settings.py
MEDIA_ROOT = '/home/jaskaran/edmhunters/media'
MEDIA_URL = '/media/'
STATIC_ROOT = '/home/jaskaran/edmhunters/static'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
root('hunt/static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'使用redbot.org测试媒体文件URL提供如下内容
HTTP/1.1 200 OK
Date: Sat, 13 Sep 2014 08:46:35 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Wed, 10 Sep 2014 17:57:24 GMT
ETag: "4b6d-502b9c8c3966e"
Accept-Ranges: bytes
Content-Length: 19309
Cache-Control: max-age=604800, public
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: image/jpeg对于静态文件,这是它输出的内容。
HTTP/1.1 200 OK
Date: Sat, 13 Sep 2014 08:49:12 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
ETag: 1409031812.69
Content-Length: 23907
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/png知道我错过了什么吗?
发布于 2014-09-14 18:33:29
您正在服务来自django (通过django-管道)的静态文件,但服务于web服务器。那么.htaccess指令就没有效果了。
https://stackoverflow.com/questions/25821494
复制相似问题