Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to avoid loading all the html files when PWA loading? #45

Open
ElderJames opened this issue Sep 20, 2024 · 1 comment
Open

How to avoid loading all the html files when PWA loading? #45

ElderJames opened this issue Sep 20, 2024 · 1 comment

Comments

@ElderJames
Copy link

I found that all the html files would be loaded, but I only want just the current one be loaded.

image

@jsakamoto
Copy link
Owner

jsakamoto commented Sep 22, 2024

Hi @ElderJames,

I found that all the html files would be loaded

The wwwroot/service-worker-published.js file generated by the default project template does that. By modifying the wwwroot/service-worker-published.js file, you can make the app load only specified HTML files for offline access.

For example, you can see the following line in your wwwroot/service-worker-published.js file.

const offlineAssetsInclude = [ /\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/ ];
                                                             // 👆 Look here.

As you can see in it, all of the HTML files, including static pre-rendered, are specified for offline assets due to the regex pattern, /\.html/. So if you change that regex pattern from /\.html/ to /^index\.html$/, your app must not load HTML files except for the root index.html file.

const offlineAssetsInclude = [ /\.dll$/, /\.pdb$/, /\.wasm/, /^index\.html$/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/ ];
                                                             // 👆 Change here to like this.

Honestly, I have not verified it, but I believe it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants