简体   繁体   中英

PWA: How to access client's locally stored version of manifest.json

In an pwa project I'm shipping an user specific manifest.json (start_url has an indiviual parameter per user).

I am currently storing this parameter in a cookie when the app is launched / start_url is browsed. But if the app cache is cleared for some reason and the user browses a subsite, the parameter is lost.

So is it possible to read the value of start_url from the client's localy stored version of manifest.json using javascript?

You can fetch them using Fetch API . Path of manifest.json can be found where you imported in html file. Eg: <link rel="manifest" href="/manifest.json">

fetch('/path/to/your/manifest.json')
    .then(res => res.json())
    .then(json => {
        console.log(json.start_url)
        // ... use them ...
    })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM