我有一個與django-tastypie
開發的REST API。我有一些相當沉重但不可變的資源,所以我希望瀏覽器緩存它們以避免不必要的請求。爲什麼瀏覽器不會緩存我的http響應?
我已經設置了HTTP Expire
頭日期遠兩年在未來,這是瀏覽器中得到什麼:
HTTP/1.1 200 OK
Date: Wed, 16 May 2012 17:29:33 GMT
Server: Apache/2.2.14 (Ubuntu)
Vary: Cookie,Accept-Encoding,User-Agent
Expires: Tue, 06 May 2014 17:29:33 GMT
Cache-Control: no-cache, public
Content-Encoding: gzip
Access-Control-Allow-Origin: *
Content-Length: 1051
Keep-Alive: timeout=15, max=82
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
我使用jQuery.ajax
發出請求。 expires頭文件看起來不錯,但每次刷新頁面時都會發出請求。
工作,謝謝!另外,我發現當前版本的'django-tastypie'強制'Cache-Control:no-cache'頭。所以我必須根據這個拉取請求來改變它:https://github.com/toastdriven/django-tastypie/pull/380 –