{"repo":"ricokahler/next-plugin-preval","free":true,"listed":false,"github":"https://github.com/ricokahler/next-plugin-preval","clone":"git clone https://github.com/ricokahler/next-plugin-preval.git","description":"Pre-evaluate async functions during builds and import them like JSON","language":"TypeScript","stars":253,"topics":["nextjs","preevaluation","jamstack","ssg"],"license":"MIT","category":"saas-starters-boilerplates","readme_excerpt":"next-plugin-preval · Pre-evaluate async functions (for data fetches) at build time and import them like JSON Why? The primary mechanism Next.js provides for static data is getStaticProps — which is a great feature and is the right tool for many use cases. However, there are other use cases for static data that are not covered by getStaticProps . - Site-wide data : if you have static data that's required across many different pages, getStaticProps is a somewhat awkward mechanism because for each new page, you'll have to re-fetch that same static data. For example, if you use getStaticProps to fetch content for your header, that data will be re-fetched on every page change. - Static data for API routes : It can be useful to pre-evaluate data fetches in API routes to speed up response times and offload work from your database. getStaticProps does not work for API routes while next-plugin-preval does. - De-duped and code split data : Since next-plugin-preval behaves like importing JSON, you can leverage the optimizations bundlers have for importing standard static assets. This includes standard code-splitting and de-duping. - Zero runtime : Preval files don't get sent to the browser, only their outputted JSON. See the recipes for concrete examples. Installation Install or Add to next.config.js Usage Create a file with the extension .preval.ts or .preval.js then export a promise wrapped in preval() . Then import that file anywhere. The result of the promise is returned. When you i","default_branch":null,"files":null,"tree":[],"storefront":"/r/ricokahler","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/ricokahler/next-plugin-preval/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}