O'Reilly logo

Web Development with Node and Express by Ethan Brown

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required