barbajs/barba

First page load is not cached, but could be fetched automatically in background

Closed this issue ยท 8 comments

Barba caching is not working on first page load.

When loading the home, the page won't be cached.
Navigating to another page and go back will make the home page properly cached.

Related issue #383.

Adding barba.cache.set(next.url.href, next.html, 'init'); on the once hook will cache the first loaded page.

Thanks @geraldnako for the quick workaround! ๐Ÿ˜‰

daun commented

Doesn't the (new) solution re-introduce the old issue #383 by caching the (possibly already modified) html of the current page? To make this fool-proof, one would have to fetch/preload the page in the background and cache the returned html.

Hi @daun ๐Ÿ‘‹

Thanks for pointing this out.

From what I have tested, the first page was not cached at all: Barba was making a new request when using backward navigation to the home. In order to give an appropriate answer to this, I have added it again to my notes, so I can do additional tests and give a feedback on that ๐Ÿ˜‰.

daun commented

Sounds good! Maybe this could be a setting? That way, consumers can explicitly turn it off if they run into problems with caching the already modified html.

Hi @daun ๐Ÿ‘‹

Sorry for the late feedback ๐ŸŒŠ
You are right: adding a setting is clearly the solution to make everyone happy ๐Ÿ˜‰

I will open an additional issue to make things clear.
From my point of view, that setting have to be true by default, what do you think? ๐Ÿค”

daun commented

@xavierfoucrier Wonderful! I think having it true or false is fine either way. But I guess you could choose the solution that doesn't involve a breaking change :)

@daun sure ๐Ÿ‘Œ , thanks for your feedback!