Leverage browser caching
The meaning of "Leverage browser caching"
When testing your page with GTMetrix or WebPagetest, you might see suggestions to "Leverage browser caching of static assets".
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 website load much faster for repeat visitors.
What is TTL?
The expiry time for a web file is called TTL (time-to-live). This means that if your logo has a TTL of 1 week, a returning user's browser will load it from local cache for a week. After a week passes 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 1 week or even for 1 year for assets that almost never change. However, files that change frequently should have a much shorter TTL.
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). 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 either responsive images, 360 spin or deep zoom images. These "?info" requests are dynamic AJAX (XHR) requests for information about an image. They're a key contributor to the intelligence behind Sirv's ability 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 distringuish between these dynamic files, so you might see suggestions to "Leverage browser caching" for ?info requests. As these are dynamic files (not static files), that advice would be inappropriate and your users could see 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:
- 1. Sirv's XHR requests are made after the DOM content has loaded, so they don't slow down page loading.
- 2. Google's recommended web page analysis tool PageSpeed Insights correctly treats "?info" requests as dynamic. It raises no concerns, proving that they have no negative impact on page loading or SEO.