You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it correct that the exported Init function for pages only runs in develop mode? In production it seems that the data is being loaded from the cached json-file.
Although a nice feature, I'm running into cases where I need the latest data from the server to be fetched and hydrate any content from cache. For example: I have a website where pages can be created inside a CMS. When building the website all the pages are pre-rendered and cached, which is amazing. However, whenever I make a small change inside the content for the page I would need to rerender the full website in order for that change to be visible. With the previous version the Init function would also still run in production mode. So the browser renders the static version from the server. Then the Init-function fetches the latest version from the server and goes ahead and updates the content that was changed. So I get the lastest version no matter what.
Is that still possible with the current version of hyperstatic?
The text was updated successfully, but these errors were encountered:
I think you could achieve what you're looking for by creating a hyperapp http effect similar to the loadStatic one in the init of your pages, example:
// in some utils file...constpromiseLoaderFx=async(dispatch,{ loader, action, error }){try{constdata=awaitloader();dispatch([action,data])}catch(e){dispatch([error,e])}}constpromiseLoader=(args)=>[promiseLoaderFx,args]// In you page file..exportconstinit=(state,location)=>[state,loadStatic({loader: async()=>{constdata=awaitgetPageData(`https://foobar.com/api/${location.params.id}`)returndata},action: HandleData,error: HandleError}),promiseLoader({loader: async()=>{constdata=awaitgetPageData(`https://foobar.com/api/${location.params.id}`)returndata},action: HandleData,error: HandleError}),]
This will load the data as usual via the hyperstatic json cache, but then also via your live API at runtime (in production)
Hmm that sounds like a good idea. But that doesn't trigger the promiseLoader effect on navigation. So I guess I have to add the same function to the pageChange callback as well. Is that correct?
Is it correct that the exported Init function for pages only runs in develop mode? In production it seems that the data is being loaded from the cached json-file.
Although a nice feature, I'm running into cases where I need the latest data from the server to be fetched and hydrate any content from cache. For example: I have a website where pages can be created inside a CMS. When building the website all the pages are pre-rendered and cached, which is amazing. However, whenever I make a small change inside the content for the page I would need to rerender the full website in order for that change to be visible. With the previous version the Init function would also still run in production mode. So the browser renders the static version from the server. Then the Init-function fetches the latest version from the server and goes ahead and updates the content that was changed. So I get the lastest version no matter what.
Is that still possible with the current version of hyperstatic?
The text was updated successfully, but these errors were encountered: