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

Support for fully offline search like PWAs #59

Open
geshan opened this issue Aug 18, 2022 · 8 comments
Open

Support for fully offline search like PWAs #59

geshan opened this issue Aug 18, 2022 · 8 comments
Labels
improvement Not a bug Pagefind Search The web-facing search js/wasm API

Comments

@geshan
Copy link

geshan commented Aug 18, 2022

Pagefind is a great project and a boon to static/JAM stack websites.

I run a blog that is also a Progressive Web Application (PWA) and I thought as page find is fully client side it would work offline for a PWA. Unfortunately, that was not the case, the main blocker I found was the metadata timestamp call. I have made sure that all the .pf_fragment, .pf_index, .pagefind, pf_meta files are cached by the service worker, still when the server is not there, the /_pagefind/pagefind.pf_meta?ts={current-ts} fails and the search fails too. Is there a way to also be cached by the service worker so that the search works offline? May be not the latest index but whatever was cached. I may be oversimplifying it.

Patch fix

If I force remove the ?ts={current-ts} it kinda works fully offline, is there a way to remove it with a flag or something?

@bglw
Copy link
Contributor

bglw commented Aug 18, 2022

I'm not particularly on top of PWAs, but I could definitely add an option for configuring that query parameter. That would let you specify a custom query parameter rather than using the timestamp automatically, but would still allow you to set a new parameter on each build if you ran into caching issues. I'll wire that up 🙂

@bglw bglw added the Pagefind Search The web-facing search js/wasm API label Aug 18, 2022
@geshan
Copy link
Author

geshan commented Aug 18, 2022

@bglw that would be really helpful, then I can replace my google search with Pagefind and it will work fully offline too.

@bglw
Copy link
Contributor

bglw commented Aug 18, 2022

Grand! I'll include that in the next release.

@bglw bglw modified the milestones: v0.8.0, v0.8.0 (Multisite) Aug 19, 2022
@bglw
Copy link
Contributor

bglw commented Aug 23, 2022

Hi @geshan — unfortunately there wasn't a super simple way to drop this in with the latest release. This file is loaded on initialization before any options get passed to Pagefind in the browser, so there isn't a great way to connect this to a flag in a nice way. (and I'm hesitant to make it a build-time flag)

For now, after running pagefind you could automatically patch out that query parameter each time:

# Linux
pagefind && sed -i 's/?ts=${Date.now()}//g' public/_pagefind/pagefind.js

# MacOS
pagefind && sed -i '' 's/?ts=${Date.now()}//g' public/_pagefind/pagefind.js

I will keep ruminating on this though and try find a better solution that I'm comfortable with 🙂

@geshan
Copy link
Author

geshan commented Aug 23, 2022

Sounds fine for now, thanks!

@bglw bglw added improvement Not a bug collecting opinions Leave a +1 or a comment! labels Sep 25, 2022
@alaminkouser
Copy link

Hi @geshan — unfortunately there wasn't a super simple way to drop this in with the latest release. This file is loaded on initialization before any options get passed to Pagefind in the browser, so there isn't a great way to connect this to a flag in a nice way. (and I'm hesitant to make it a build-time flag)

For now, after running pagefind you could automatically patch out that query parameter each time:

# Linux
pagefind && sed -i 's/?ts=${Date.now()}//g' public/_pagefind/pagefind.js

# MacOS
pagefind && sed -i '' 's/?ts=${Date.now()}//g' public/_pagefind/pagefind.js

I will keep ruminating on this though and try find a better solution that I'm comfortable with 🙂

It works for now and also works in GitHub Workflows. And yes, it needs a better solution.

@bglw
Copy link
Contributor

bglw commented Nov 17, 2023

Ah, I had forgotten about this issue but I'll pencil in proper support soon! As of Pagefind 1.0, the file is not loaded on initialization, and passing options could totally influence this behavior, so I can certainly add an option to resolve this. I'll target the next release for that 🙂

@bglw bglw removed the collecting opinions Leave a +1 or a comment! label Nov 17, 2023
@bglw bglw added this to the Next patch release milestone Nov 17, 2023
@sanabel-al-firdaws
Copy link

this feature is important many people use lunr over pagefind because it works fully offline

i maneged to cache everything on the pagefind folder even the entry.json but when it dose the ?ts= it dosen't work because it can't get date offline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Not a bug Pagefind Search The web-facing search js/wasm API
Projects
None yet
Development

No branches or pull requests

4 participants