Back to blog

Static generation vs dynamic serving

Tuesday, 03 January, 2017

Wouldn’t it be easier to just build the page once?

Let’s talk about a website, say a simple blog such as this very page you are reading right now. It has a logo, menu, title, each blog entry has its own title, some images, date of creation and some text. All this content is usually stored in a database and each time somebody visits, the server gathers all this content, builds the page and serves it to the visitor.

What is static serving?

With enduro.js, the page is built only on content change. When visitors come and request the page it’s already in a form of a prebuilt .html page and ready to be served.

Cheaper hosting

The static website can be served by a very simple and cheap server, in some cases even for free(such as github pages).

Blazing speeds

Having ready-made .html pages means there is no processing needed to serve the page. It’s just a matter of requesting a file and sending the file. Moreover, the file can be located on a CDN network for even faster delivery.

Consistent delivery

By not using any of the server’s resources there is less chance of a lag on the server causing inconsistent delivery times. Random traffic peak can cause many users to have to wait for your page to be delivered.

Simplicity

Building the page each time somebody requests it allows errors to creep in anytime. When you pre-build the page you know each user will always receive this exact page. Every time.

Drawbacks

Obviously this approach works only for websites that should serve the same thing to all users, such as this one you are reading right now.

  • Displaying personalized content is more difficult.
  • Logging in is an absolute no-go with this approach
  • Time-related information such as ’10 minutes ago’ is harder to do.

Using javascript to fill these use cases

In most cases, javascript can be used to add personalized content or content that is dependant on something dynamic. Enduro.js can and is used to make web-apps that load dynamic content after the initial page load, which is still pregenerated. When users can log into a website, using one-page web apps such as gmail is a modern way to approach this anyways.

enduro.js is not just a static page generator

Enduro.js is built on top of node.js and express. It is absolutely ok and easy to build a dynamic page with enduro. This way, enduro.js allows you to mix static and dynamic pages to achieve maximum efficiency.

Cache

Most of the speed penalty dynamic serving causes can be mitigated by using caching. For example, for WordPress there is a [cache plugin].(https://wordpress.org/plugins/w3-total-cache/). This however adds complexity by having a dynamically built pages and then adding a layer that is trying to save the pages instead of just pre-building the pages in the first place.

Further reading

Noah Veltman explains static vs dynamic serving as a vending machine vs a restaurant. Very clever, read it here: http://noahveltman.com/static-dynamic/

Back to blog

Shout out to pexels and freepik