Dulcie @ 2021 By : Template Sell.

Category: http

[http] Last-Modified, If-Modified-Since, ETag 和 If-None-Match 介紹

在上一篇介紹了  http 關於 cache 的 header ,但當 cache 過期或是需要 revalidate 時又是如何運作的呢? 此篇將介紹幾個常見的 revalidate 的 http header Last-Modified, If-Modified-Since (RFC 7232) request If-Modified-Since: 上次 Last-Modifed 回傳的時間 用於做 revalidate 時,檢查檔案在指定時間後是否有被變更,若有回傳 200 及新的檔案內容,反之則回傳 304 (Not Modified) 即可。 response: Last-Modified: 檔案在伺服器最後修改的時間 在 response 帶回此檔案上次在伺服器被修改的時間,以備做 revalidate 時發送的 timestamp。 實際上的使用情境會像是以下步驟: client 發 request 與伺服器要 image.png 檔案 server 回傳 Cache-Control: max-age=86400, no-cache ,  Last-Modified: Wed, 21 Oct 2018 […]

[http] http header, Cache-Control, Expires 用法說明

在優化網頁速度時,常會使用 cache 的機制來減少 server 負載, client 資源等待時間。 比如 server 前面會架一台 cdn 服務, cache 一些靜態檔案…等等。 server 可能會使用 redis, 來 cache 需要做大量計算的結果,降低負載。 這篇則是要介紹有哪些 http header 可以善用在 client 端(瀏覽器)來優化網頁速度,檢查是否有成功 cache 可以參考此篇文章 Expires 最早在 http 1.0 就存在的 header, 使用方式為 Expires[date] (日期格式必須符合 RFC1123) 例如: Expires: Wed, 5 Mar 2018 11:00:00 GMT 用法為設定一個確切的日期,當 client 端時間小於 response header (Expires) 時間時,則會使用 cache. 由於 client […]