Caching in weweb

Can I cache my fetched data, so I don’t refetch everytime I visit the same page?

Do you want to cache between page change or between multiple visits ?

In the first case, here my solution :

  1. disable auto fetch on your collection

  2. Create a page workflow that will fetch your collection (if not already fetched)

Your collection should now fetch once per visit and persist between page change, but not between visit.
In this case you will need one more step, you will have to store your collection data into another variable with local storage enabled, but that will require you to use this variable everywhere instead of your collection and you will lose all feature related to collection so I don’t recommend that.

Edit : I forgot the isFetched metadata available, so you don’t need an extra variable to keep this information

1 Like

wow this is a genius workaround. And it is possible because of how weweb works. I think it is really clean. Thank you @Alexis . I think however, this is a really crucial feature that is really important for performance and user experience. I hope you guys make this feature built in as easy as the ‘fetch automatically’ toggle, maybe in the next performance update. As If one have tons of collections, it is really repetitive and alot of work using the workflow.

1 Like

Hi @Alexis sorry I tried it but the data doesn’t seem to persist. It loads on initial load, and when revisitting it doesn’t load anything. Do you know what I might done wrongly?

My bad, don’t persist your isDataFetched in local storage, because your data are not, sorry
If your variable is persisted, your collection will not fetch once you revisit or reload, you only need your variable during your navigation so you don’t need to persist it.

Edit1: And yes, I think we could provide another mode “fetch this collection once”

Edit2: Oh, and you don’t need to create this variable because I forgot she already exist in the collection metadata

1 Like

Thank you, that makes sense, finally got it. Much cleaner now as I don’t need to create custom variables for each collection. Thank you :pray:

May I suggest you guys expand the topics? Making it more accessible by categorizing them? For example this thread would be in ‘Performance’ topics. Other could include layouts, backend/data, workflows, custom javascript, auth, etc… I like reading threads to find informations and for example this would be useful for performance, I gained atleast 2x load speed with it.

@Alexis I think it cached and make my page load faster, but it still flashes for a sec before showing up, the static html load first and only then the cached shows up, what do you think is the reason and can I overcome this?