Chapter 16. Static Content

Static content refers to the resources your app will be serving that don’t change on a per-request basis. Here are the usual suspects:

Multimedia
Images, videos, and audio files. It’s quite possible to generate image files on the fly, of course (and video and audio, though that’s far less common), but most multimedia resources are static.
CSS
Even if you use an abstracted CSS language like LESS, Sass, or Stylus, at the end of the day, your browser needs plain CSS,[10] which is a static resource.
JavaScript
Just because the server is running JavaScript doesn’t mean there won’t be client-side JavaScript. Client-side JavaScript is considered a static resource. Of course, now the line is starting to get a bit hazy: what if there was common code that we wanted to use on the backend and client side? There are ways to solve this problem, but at the end of the day, the JavaScript that gets sent to the client is generally static.
Binary downloads
This is the catch-all category: any PDFs, ZIP files, installers, and the like.

You’ll note that HTML doesn’t make the list. What about HTML pages that are static? If you have those, it’s fine to treat them as a static resource, but then the URL will end in .html, which isn’t very “modern.” While it is possible to create a route that simply serves a static HTML file without the .html extension, it’s generally easier to create a view (a view doesn’t have to have any dynamic content).

Note that if you are building an ...

Get Web Development with Node and Express now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.