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.
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.
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.
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 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:
- 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.