Hi, I’m facing an issue in WeWeb. Automatic fetch is already enabled, but I still have to add “fetch collection” on each page. Because of this, every time a user visits a page, the fetch collection call runs again.
My requirement is that when the user opens the website, all required collections should load once and then be available globally across all pages.
Currently, if I don’t add fetch collection on a page, the data is not available there. Also, when the website is refreshed, collections sometimes become empty even though automatic fetch is enabled.
Is there any way in WeWeb to fetch collections once at app start and reuse them across the entire website instead of calling them again on every page?
If “Fetch this collection automatically” is enabled, it should fetch the collection if it’s used on the page.
To make sure it doesn’t fetch that collection again when the user goes on another page that also uses the collection, you’ll need to also enable “Preserve on navigation”:
One thing to note, on app start, even if all the collections are set to “Fetch automatically”, the app will only fetch the collections active on the first page of the app. That’s best practice because there’s no point in fetching data your user may never require during their visit but you can have a workflow on app load to change the behavior if you’d like.
Does that help?
PS: I’m attaching an article about how to optimize collection loads in case you’re interested in learning more and haven’t come across it already: Intro to collections | Documentation
I think as well if the collection is on the page but in something that is conditionaly rendered it wont be auto fetched. In these cases you could use a fetch on mounted of the element