OnlyTheRecipe icon indicating copy to clipboard operation
OnlyTheRecipe copied to clipboard

Pre-rendering/Static Generation

Open jpbulman opened this issue 3 years ago • 2 comments
trafficstars

Long term, it'd be nice to have a firebase store (or something easy) that would keep a JSON of the recipe information for each URL. Then, pages could be prerendered by Next

jpbulman avatar Jan 28 '22 03:01 jpbulman

I think you may be able to do this without using a Firebase store. In recipes.tsx you can move your fetching logic out of useEffect and into a function called getServerSideProps. Then all of the fetching will happen on the server side before the page is rendered and your component will receive { ingredients, directions, title, domainIsSupported } as props.

UnsolvedCypher avatar Feb 06 '22 16:02 UnsolvedCypher

Ah okay, my mistake. I was under the impression that getServerSideProps would still result in certain client side rendering, but it looks like that would still work for SSR!

I think for SSG though, it would require some sort of db like this so it could fetch all the data during the initial build, then just serve the pre-built (generated) pages.

Since this is super lightweight in the first place, SSR would probably suffice. I don't think squeezing every last drop of performance with SSG is necessary, especially with all the extra setup it would require.

jpbulman avatar Feb 20 '22 02:02 jpbulman