Using a Content Delivery Network

Turbo 360
turbo360
June 22nd, 2020
0 points
View Demo

Hosting static assets (images, CSS, JS, pdf, etc) on a content delivery network can be tricky if you have to set it up from scratch. Luckily, all Turbo 360 sites come equipped with a built-in global CDN which is very easy to plug in. All that is required is the {{{cdn}}} prefix to any static asset references in the HTML and bingo - the asset will be served from the Turbo 360 content delivery network. To see how it work, take a look at the sample code below.

Route

The index.js route file is very simple. On the homepage request ("/"), we grab the context object from the request and pass it in as data to the index Mustache template. The context object provides key meta data about the current site such as the ID, url, name and most importantly in this case - the CDN url.

routes/index.js:

Template

The index.mustache template shows two images: one from the CDN (line 32) and one from the main app server (line 39). Note the {{{cdn}}} Mustache template placeholder on line 32. This value gets replaced by the actual CDN for the specific site and is provided in the "context" object from the index.js route file above.

views/index.mustache:

Every Turbo 360 site comes with its own CDN environment and is provided in the context object from the request. It is best practice to use this for all static assets as it optimizes delivery speed to your end user based on his or her location around the world. Note that we use the CDN also to serve the Bootstrap CSS file on line 10.

Assets that are served directly from the main site server (line 39) always come from the same location no matter where the user is located. This can lead to longer load times, higher bounce rates, and an overall poor user experience. We highly recommend that you take advantage of this feature on Turbo 360 since it is free and is a much more professional way to manage your static assets.

Join Free

Join for free today and deploy your site in seconds


Already have an account? Sign in HERE