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

Generated page links are incorrect #13

Closed
kireerik opened this issue Jun 7, 2023 · 21 comments
Closed

Generated page links are incorrect #13

kireerik opened this issue Jun 7, 2023 · 21 comments

Comments

@kireerik
Copy link

kireerik commented Jun 7, 2023

example:

generated:

  • index.html
  • page/index.html

expected:

  • /
  • page
@tatethurston
Copy link
Owner

@kireerik This is the expected behavior. It sounds like you’re requesting that this be made configurable to accommodate your hosting setup? What is the error you’re encountering? Is your web server unable to serve these assets?

@kireerik
Copy link
Author

kireerik commented Jun 7, 2023

Yes, I guess if someone wants to use the output locally then this can be a good default.

I serve (static HTML) pages as usual. On /page for example (and not at /page/index.html).

@tatethurston
Copy link
Owner

@kireerik Are you running into an issue? I suspect this works as is for your use case:

https://developer.chrome.com/docs/workbox/modules/workbox-precaching/#incoming-requests-for-precached-files

@kireerik
Copy link
Author

kireerik commented Jun 8, 2023

Yes, I think the pages are not precached like this as is because for example /page exists and is served, but /page/index.html is not served because it is not a valid route that I will serve. I only serve pages (and not html files).

@tatethurston
Copy link
Owner

@kireerik what are you using to serve your web pages?

@kireerik
Copy link
Author

kireerik commented Jun 9, 2023

Firebase Hosting

@tatethurston
Copy link
Owner

@kireerik if you make a web request to one of your pages, eg page/index.html do you get a response back from your server?

@tatethurston
Copy link
Owner

tatethurston commented Jun 10, 2023

@kireerik if you set build.format to page does this resolve your issue?

I’ll think on whether I’ll have this plugin set the that option, or inspect the config value and configure the service worker generation accordingly.

@kireerik
Copy link
Author

No, I don't get a response. Currently it is redirecting, but I might change it so that it would return a 404 page or the server would not respond or something like that.

There is no such build.format. Only file and directory which does not make a difference.

@tatethurston
Copy link
Owner

@kireerik sorry yes I mean file for the build option, which will change your generated files from page/index.html to page.html. This in turn will make the service worker precache route page.html instead of page/index.html.

@kireerik
Copy link
Author

Yes I am already using file, but it should point to page (and not to page.html).

@tatethurston
Copy link
Owner

tatethurston commented Jun 14, 2023

@kireerik page and page.html should be handled identically: https://developer.chrome.com/docs/workbox/modules/workbox-precaching/#clean-urls. The .html extension is expected in the generated service worker.

Is there a specific issue you're encountering, other than the generated service worker not looking the way you expected? Is your concern that your pages are not being cached, and you're unsure of how to test that?

@kireerik
Copy link
Author

Yes, it is not preloaded, because it should point to the correct path (not including .html).

@tatethurston
Copy link
Owner

@kireerik is the site public? Can you share the link?

@kireerik
Copy link
Author

Sure:

 
example:

@tatethurston
Copy link
Owner

@kireerik It doesn’t look like you have a service worker deployed to that domain. Could you deploy the service worker?

@kireerik
Copy link
Author

Yes, I didn't introduce it because of this issue.

@tatethurston
Copy link
Owner

@kireerik I think this is a misunderstanding, as opposed to something that requires a change to this library. If you deploy a version of your site with the service worker enabled, I'm happy to help you debug.

Alternative, take a look at my blog, https://www.tatethurston.com/, which uses this library. Note that the pages are served by the service worker, even though they are requested without the .html extension.

@kireerik
Copy link
Author

Maybe with your blog the reason for that is because you make them available with the .html extension as well.

@tatethurston
Copy link
Owner

tatethurston commented Jul 24, 2023

The current settings match the defaults for most web servers. Under the hood, this library is a light weight wrapper around workbox-build. Workbox build generates the precache urls from the filesystem.

If you find a way to achieve what you want using workbox build I’m happy to consider an addition to this library.

But the best path forward to achieve the constraints you’ve outlined is to have Astro generate pages without an html extension, or add a processing step that removes them. I’m unsure if this functionality already exists.

@tatethurston
Copy link
Owner

@kireerik My blog is currently hosted on AWS Amplify. I pushed it to Cloudflare pages, which includes redirects to extensionless pages out of the box: https://blog-5hp.pages.dev. Note that eg /about.html is redirected to /about:

curl -I https://blog-5hp.pages.dev/about.html
HTTP/2 308
date: Mon, 24 Jul 2023 23:54:48 GMT
location: /about

And the service worker works as expected.

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