How does the browser work with expiration headers, cache control headers, last modified header?

I am a web developer, worked with PHP and .NET. Having more than a year of experience working on the Internet, I could not fully understand the features of browser caching, I hope that a web guru will help here. The questions I have in mind are:

  • How does the browser really cache the material, whether it asks if the cached file has changed on the server or not,
  • Which is an ideal way for a developer to fully utilize browser caching, but also the ability to push new changes to it without any problems. I think that if the browser somehow caches my CSS and JS and images, and then checks their modification on the server each time, this may solve the problem. but I'm not sure how to do this.
+5
source share
3 answers

This blog post can help:

http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/

It explains how to use caching, while maintaining the ability to make changes when necessary.

+4
source

CSS " " :

<link rel="stylesheet" href="http://mysite.com/styles.css?v=1">
<link rel="stylesheet" href="http://mysite.com/styles.css?v=2">
...

.

+2

, .

<script src="script.js?<?= uniqid(); ?>">
<img src="myfile.jpg?<?= uniqid(); ?>">

, , , , , , .

, , , HTML5, . , .

Just remember that if you change something in the JS, CSS, Image file, and you need to push this change to regular visitors, you also need to update the manifest file. You can add as the publication date as the browser knows that this is a new manifest and it will download everything again.

0
source

All Articles