New feature: routing dynamic content through a CDN

We have implemented a new feature, which makes PoP behave like a static site generator: most content in the website, by nature “dynamic” or mutable, is made “static” or immutable by serving it through a Content Delivery Network (CDN).

If you inspect the Network using Chrome’s Developer Tools, and click on this link: https://getpop.org/en/implement/, you can appreciate that the actual requested URL is this one:

https://content.getpop.org/en/implement/?target=main&module=settingsdata&output=json&v=0.237&theme=wassup&thememode=simple&themestyle=swift

contentcdn-networktab

The important thing here is the domain has changed: it went from https://getpop.org to https://content.getpop.org, and this domain corresponds to a CDN. If the requested page is already cached in the CDN, it is returned immediately; if not, the CDN requests it from the original source, i.e. https://getpop.org, and then caches for all subsequent access.

To validate this, we can see the returned headers using curl:

curl -I "https://content.getpop.org/en/implement/?target=main&module=settingsdata&output=json&v=0.237&theme=wassup&thememode=simple&themestyle=swift"

And we obtain:

...
X-Cache: Hit from cloudfront
...

What happens when the content changes, eg: when a post gets updated, or when there is a new post which must be added in the homepage? How do we know that the content has changed? To solve this, we add an additional parameter to the URL: a thumbprint, or “tp”, denoting the last time any post/comment/user/tag was created/updated, or any combination of them.

The latest thumbprint values are retrieved frequently from the server, so the users will always be able to access the latest version of the website. What combination of thumbprints is need can be defined on a page-by-page basis, or using URL patterns (eg: define a rule that everything under /posts/ uses a combination of post + user thumbprints)

Eg: clicking on https://getpop.org/en/blog/coming-soon-serving-dynamic-cms-content-through-a-cdn/, produces:

https://content.getpop.org/en/blog/coming-soon-serving-dynamic-cms-content-through-a-cdn/?target=main&module=settingsdata&output=json&v=0.237&theme=wassup&thememode=simple&themestyle=swift&tp=1490737251.1491829696

The important bit here is tp=1490737251.1491829696: this thumbprint is composed of two values (separated by a dot): the post thumbprint, and the user thumbprint. This way, any time a user or post is created/updated, the thumbprint is regenerated, and the latest content will be cached in the CDN.

More technical considerations can be found in this blog post.

What are the advantages?

Cheaper hosting: websites with high traffic can reduce their hosting costs, since content is mainly served from the CDN instead of the server.

Faster: CDN data-centers are located near the user, thus greatly reducing latency and boosting the overall website speed.

WordPress is still there: content is still created dynamically, through WordPress. The static version of the website is generated on runtime.

Enjoy!

Welcome to the PoP framework!
Break the information monopoly

the PoP framework is open source software which aims to decentralize the content flow and break the information monopoly from large internet corporations. Read more.


Sign up to our newsletter: