HTML5 cache manifest no cache for html file itself

前端 未结 3 2320
小蘑菇
小蘑菇 2021-02-14 08:33

index.php:


cache.manifest

CACHE MANIFEST

CACHE:

/img.png
FALLBACK:
/ /offlin         


        
相关标签:
3条回答
  • 2021-02-14 09:09

    I had the same problem.

    I used an iframe to load a page called 'go_offline.html' this page has the manifest attribute on the html element and some dummy content.

    the iframe is hidden using css

    this way only the dummy page is cached and all requests are caught by the fallback page in the .manifest file

    0 讨论(0)
  • 2021-02-14 09:10

    I have tried the iframe work around, and find it ripe with errors. Most browsers cache the data for the iframe where the page cannot get it.

    Instead make the page's content load via AJAX. Basically have a blank html page with the manifest and javascript which pulls and adds its content from the server. This way only the blank html is cached, and content is always updated from the server.

    Converting a page to this method can be very difficult, but it works. Making sure the appropriate javascript gets run at the correct time, probably requires some detangling. Moving around server code which won't be called when pulling from cache to the new ajax method.

    Note: no need to pull conditional content from the server if the condition is in the query string, different query strings make a separate cache

    0 讨论(0)
  • 2021-02-14 09:33

    No, the file which references the manifest is always itself cached. From the spec:

    The resource that declares the manifest (with the manifest attribute) will always get taken from the cache, whether it is listed in the cache or not, even if it is listed in an online whitelist namespace.

    0 讨论(0)
提交回复
热议问题