问题
I want the two iframes
<iframe src="www.URL.com?name=benny&runtime=1231231>
<iframe src="www.URL.com?name=benny&runtime=757847584>
which are loaded at different times to be mapped to the same cached value in the browser. The server has nothing to do with this. Basically, is there a way to have chrome, firefox, etc... cache api ignore certain parameters (in this case 'runtime') when looking up a src.
Passing a separate param or making a separate call for runtime will not work in the use case
回答1:
That is not possible. You need to either remove parameters with different values from src or use XMLHttpRequest and blobs to request resource, and remove parameters from request URI using JavaScript. If you will use XMLHttpRequest you also need to consider Same-origin policy.
Browser cache key is a combination of HTTP method and URI. Query parameters are a part of an URI. Relevant excerpt from HTTP 1.1 specification:
The primary cache key consists of the request method and target URI. However, since HTTP caches in common use today are typically limited to caching responses to GET, many caches simply decline other methods and use only the URI as the primary cache key.
For more information check New Tricks in XMLHttpRequest2 article by Eric Bidelman, XMLHttpRequest page, Blob Web APIs page and Same-origin policy page on MDN.
If you control server that serves your resources you can also adjust it to vary cache entries by certain parameters. For example in ASP.NET MVC you can use VaryByParam property of a OutputCache attribute. For more information check Improving Performance with Output Caching article by Microsoft ASP.NET team.
来源:https://stackoverflow.com/questions/41615716/instructing-browser-cache-to-ignore-certain-url-params