国产欧美日本一区二区三区免费_在线午夜日韩_青久视频_91麻豆国产精品91久久久_天天干天天插天天射_天天操夜夜操B天天拍_亚洲精品第一永久地址911_色一情一乱一伦一区二区三区 _精品入口免费_中文成人精品视频久久视频_桃色播播_91嫩草香蕉国产线懂你的网站_日产国产亚洲A片无 码_久久精彩免费视频_永久精品大片www._精品国产成人_日日碰狠狠添天天爽无码av

Use browser cache

Dec 22, 2015
PageSpeed ??Insights
0
On this page

This rule is triggered when PageSpeed Insights detects that your server response does not contain an explicit cache header or that some resources are specified to be cached only for a short period of time.

Overview

Browser caching of static resources can save users time if they visit your site multiple times. Cache headers should be applied to all cacheable static resources, not just to a small number of static resources (for example, pictures). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, and so on). Typically, HTML is not a static resource and should not be considered a cacheable resource by default. You should consider which caching policies apply to the HTML of your website.

Recommendations

為您的服務(wù)器啟用瀏覽器緩存。靜態(tài)資源應(yīng)該至少有一周的緩存有效期。廣告或小部件這類的第三方資源也應(yīng)該至少有一天的緩存有效期。對于所有可緩存資源,我們建議您進行以下設(shè)置:

  • ExpiresSet it to a future date, at least one week and at most one year (we tend to setExpires,而不設(shè)置Cache-Control: max-age,因為前者受支持的范圍更為廣泛)。請勿將其設(shè)為超過一年的將來日期,因為這樣就違反了RFC準則。
  • If you know exactly when the resource will change, you can set a shorter expiration date. However, if you think the resource "may be about to change" but do not know the exact time, you should set a longer expiration date and use URL fingerprints (as described below).

Expires and Cache-Control: max-age header

這些標頭用于指定相應(yīng)時間段,瀏覽器可在指定的這段時間內(nèi)使用已緩存的資源,而無需查看網(wǎng)絡(luò)服務(wù)器是否提供了新版資源。這些緩存標頭功能強大,沒有任何應(yīng)用條件限制。在設(shè)置這些標頭并下載資源后,瀏覽器不會為資源發(fā)出任何GET請求,除非過期日期到期或達到時間最大值,亦或是用戶清除了緩存。

Last-Modifed和ETag標頭

這些標頭可用于指定瀏覽器應(yīng)如何確定用于緩存的文件是否相同。在Last-ModifiedThe date is specified in the header, while the date specified in theETag標頭中指定的則可以是唯一標識資源的任意值(通常為文件版本或內(nèi)容哈希值)。Last-Modified是功能“較弱”的緩存標頭,因為瀏覽器會使用試探法來確定是否需要從緩存中抓取內(nèi)容。

With these headers, browsers can effectively update their cached resources by issuing a conditional GET request when the user explicitly reloads the page. A conditional GET request does not return a complete response unless you change the resource on the server side, so such a request has less latency than a complete GET request.

我應(yīng)使用哪個緩存標頭?

對于所有可緩存資源,指定一個ExpiresCache-Control max-ageAnd aLast-ModifiedETag至關(guān)重要。您沒必要同時指定ExpiresAndCache-Control: max-age;或同時指定Last-ModifiedETag。

Use URL fingerprints

對于偶爾發(fā)生變化的資源,我們可以讓瀏覽器緩存相應(yīng)的資源,直到該資源在服務(wù)器上出現(xiàn)變化,而服務(wù)器則在此時通知瀏覽器有新版本可用。我們可以通過為每個版本的資源指定一個唯一網(wǎng)址來實現(xiàn)這一目的。例如,假定我們有一個名為“my_stylesheet.css”的資源。我們可以將文件重命名為“my_stylesheet_fingerprint.css”。當資源發(fā)生變化時,其指紋就會發(fā)生變化,對應(yīng)的網(wǎng)址也會隨之更改。網(wǎng)址一經(jīng)更改,系統(tǒng)就會強制瀏覽器重新抓取資源。通過指紋,我們甚至可以為變化更為頻繁的資源設(shè)置將來的過期日期。

指紋識別的常用方法是使用對文件內(nèi)容的哈希值進行編碼的128位十六進制數(shù)。

另一個策略是直接為新版應(yīng)用創(chuàng)建新版目錄,然后為版本目錄中的各個版本放置所有資源。這樣做的缺點是,如果各個版本中的資源未發(fā)生變化,則其網(wǎng)址將仍會更改以強制重新下載。使用內(nèi)容哈希值不會遇到該問題,但這種方法稍微復(fù)雜一些。

?

Except as otherwise noted, the content of this page is licensed under the?Creative Commons Attribution 3.0 License, and code samples are licensed under theApache 2.0 License. For details, see our?Site Policies.

Nickname*:
E-mail*:
Rate*:
Comments*:

If you need to get in touch with us, here are our contact details

If you need to get in touch with us, here are our contact details
Contact number
Contact email
WeChat Contact
Jieying Network
QQ