Leverage browser caching
When testing your page with GTMetrix or WebPagetest, you might see suggestions to "Leverage browser caching of static assets". This is usually good advice, but not always. Let's review when you should take action and when you shouldn't.
What is browser caching?
Each time a browser opens a web page it downloads all the files that make up the page (images, media files, CSS, JS and HTML). The web servers which serve these files to the browser assigns special headers to each file, telling the browser which assets should be cached and for how long. This way, when your visitors open a page they won't have to download all the web files every time, thus making your web page load faster for repeat visitors.
What is TTL?
The expiry time for a web file is called the TTL (time-to-live). It is set as a duration, such as 7 days or 30 days. If an image has a TTL of 7 days, a user's browser will load it from local cache for up to 7 days. After 7 days has passed, the next time your browser requests it, it'll download the logo again and store it in its local cache for another 7 days.
The general guideline is to set TTL for 7 or 30 days. You could even set 1 year for assets that almost never change. However, files that change frequently should have a shorter TTL or a user's browser might show an old cached file.
What are Sirv's TTL settings?
Sirv sets a default TTL of 7 days for your images, which can be adjusted in your Default profile (or other profiles). Possible values are 1 hour; 3 hours; 12 hours; 1 day; 7 days; 30 days; 1 year.
Regardless of the TTL in your profile, Sirv caches your processed images long-term, so they're ready for rapid serving to future visitors. Sirv only deletes processed images if the master image changes.
Sirv's "?info" requests and browser caching
Sirv also sends tiny information requests if your page uses sirv.js for responsive images, 360 spin or deep zoom images. These "?info" requests have a TTL of 5 minutes because they are dynamic AJAX (XHR) requests for information about an image. They're contribute to Sirv's capability to responsively generate and serve the most perfectly sized and optimized images/spins/zooms.
GTMetrix and WebPagetest analysis tools do not yet have the ability to distinguish between these dynamic files, so you might see suggestions to "Leverage browser caching" for ?info requests. As these are dynamic files (not static), that advice wouldn't be appropriate as it could lead to your users seeing images of the wrong size or style. Therefore, you should ignore caching advice for ?info requests.
It's worth understanding some other facts about AJAX (XHR) requests:
- Sirv's XHR requests are made after the DOM content has loaded, so they don't slow down page loading.
- Google's recommended web page analysis tool PageSpeed Insights correctly treats "?info" requests as dynamic. It raises no concerns, demonstrating that they have no negative impact on page loading or SEO.