javascript - Manipulating browser cache -
I'm developing a web app uses many asynchronous loaded images, which are often modified over time There are several problems with their URL:
-
If I do not provide images with explicit caching in the HTTP header, then the user is often given an old image The version will be available, but doing so increases the server load significantly The expertise.
How can I remove the cache control from the browser and how can I manually evaluate whether I should use a cached image or reload it from the server? -
Since many different images are being loaded, I am parallel to the image download on different hostnames (i.e.
image01.example.com
,image02.example.com
, but all these hostnames resolve for the same physical server) since the hostnameNN
is randomly generated, so I also miss the cache Where I could recover the up-to-date image from the browser cache. -
Would you recommend using cache control techniques and reading material?
-
To force a load, the URL Add a nonsense parameter to
& lt; Img src = 'http: //whatever/foo.png? X = random '& gt;
Where something like "random" millisecond timestamp will be. Now, if you want the image to be loaded only when it is replaced, then you have to make sure that your server is setting the "etag" value for images, and it is using the appropriate ending And "if modified" header. Eventually you can not take cash control from the browser in any way other than your HTTP headers.
-
Instead of creating NN randomly, make it with a hash of image name. In this way the name of the same image will always map to the same hostname, and you will still have images distributed in both of them.
-
I do not have a good suggestion, but web implementation advice is abundant on the internet, so I can say that start with Google.
Comments
Post a Comment