18 Exporting static sites with Sapper

 

This chapter covers

  • Exporting Sapper apps to generate static sites
  • When to export apps
  • An example exported app

Exporting can be desirable for apps where it is possible to generate the HTML for every page at build time.

A common example is a blog site, where users can navigate to specific posts. Authors periodically add blog posts, and the new posts only become available when the site is regenerated. Site generation can be automated so it occurs on a regular basis, such as every night. The site can also be automatically regenerated every time there is a push to its source repository.

Static sites have excellent runtime performance. One reason is that the HTML for each page only has to be downloaded, not generated in the browser or on the server. Another reason is that typically far less JavaScript code is downloaded. In some cases no JavaScript is required, such as for sites that do not require user interaction other than page navigation.

Static sites are also more secure because most or all API interactions occur during site generation, not when users interact with the site. This means there is little to no chance that server hacking can affect the content of the site.

Exporting a Sapper app is somewhat similar to the functionality provided by Gatsby (www.gatsbyjs.org/) for React. In this chapter, we will dive deep into the details of exporting and use it in an example app.

18.1 Sapper details

 
 
 
 

18.2 When to export

 
 

18.3 Example app

 
 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest