CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.22k stars 97 forks source link

[Question] "Slow" first load #598

Open gustaveWPM opened 2 months ago

gustaveWPM commented 2 months ago

Hello there!

I noticed that the first search is always slower than the others.

For example: https://pagefind.app/

If I search hello, I will have a little delay ("Searching for hello..."). Then, if I search hello again, the search will be really fast.

But if I refresh the page, then start again to search hello, I will have the little delay again.

Is it planned to populate the browser cache (like requests caching) to improve this?

bglw commented 2 months ago

The browser cache should be caching the relevant indexes/fragments, and if I do the same action as described I'm not seeing any significant delay — and the index chunks are served from my browser cache.

There is one request in the flow which is explicitly uncached, which is the request for the entry JSON file. (see https://pagefind.app/pagefind/pagefind-entry.json )

This file will never be cached, as the contents are used to cache-bust the rest of the requests. If you're on a slower connection then pulling this file might cause the small delay, but that's the only thing I can think of that would affect a refresh.

gustaveWPM commented 2 months ago

The browser cache should be caching the relevant indexes/fragments, and if I do the same action as described I'm not seeing any significant delay — and the index chunks are served from my browser cache.

There is one request in the flow which is explicitly uncached, which is the request for the entry JSON file. (see https://pagefind.app/pagefind/pagefind-entry.json )

This file will never be cached, as the contents are used to cache-bust the rest of the requests. If you're on a slower connection then pulling this file might cause the small delay, but that's the only thing I can think of that would affect a refresh.

Interesting! I'll try with someone who has a better connection and computer than me.

gustaveWPM commented 2 months ago

Indeed, this is caused by my poor hardware and connection. Sorry, I should have checked it before writing this issue.

bglw commented 2 months ago

No worries! It's still good to hear from people that the experience can be slow, I'll keep that in mind :)

gustaveWPM commented 2 months ago

No worries! It's still good to hear from people that the experience can be slow, I'll keep that in mind :)

I'm exaggerating when I say it's slow. There's just a perceptible delay in my reaction time, but I don't have to wait more than a second either.

It's only on the first request, so maybe it's due to some computations more than connection.

gustaveWPM commented 2 months ago

Oh... Finally, it looks like this is slower on Firefox than on Chrome. I'm curious.

bglw commented 2 months ago

Hmm — my primary browser is Firefox and I've never noticed an issue.

OS / Firefox version?

gustaveWPM commented 2 months ago

Hmm — my primary browser is Firefox and I've never noticed an issue.

OS / Firefox version?

Ubuntu 22.04.4 LTS x86_64 Kernel: 6.5.0-27-generic CPU: Intel i3-10110U (4) @ 4.100GHz GPU: Intel CometLake-U GT2 [UHD Graphics] Memory: 7674MiB

Firefox 125.0

Everything is faster on Chromium on this setup.