HTML5 uses cache only offline

I started using HTML5 cache to view a simple HTML page with one css file and two js files.

My problem is that the cache is being used, whether I'm offline or not. But I just want to use the cache when I'm offline . Does anyone know how to solve this?

index.html file manifest:

<html manifest="app.cache"> 

Manifest file app.cache:

 CACHE MANIFEST /index.html /css/style.css /js/jquery-1.7.1.min.js /js/functions.min.js 

Thanks!

+6
source share
2 answers

manifest = "app.cache" - not going to solve your problem. It caches the entire file specified in the manifest file. You must save your data in local storage or local db and receive data from the server / local server depending on the connection status [online / offline].

0
source

According to the standard specified in whatwg , this is possible by changing the default caching mode from fast to prefer-online state. There, the instructions should add the following at the end of your appcache manifest, after listing all the files you need offline:

 SETTINGS: prefer-online NETWORK: * 

The idea seems to be to allow basic standalone support to be added to "legacy" applications that cannot but modify the HTML document each time it is served. I have not verified that this works in any current browser.

+4
source

Source: https://habr.com/ru/post/908792/


All Articles