Instructions for Express
Define a helper function
Express allows you to output whatever HTML you wish. Here is an example how you can create a helper function to serve and optimize your static files via Tinify CDN.
const app = express();
app.locals.assetUrl = function(path) {
return "https://xxxxxxxx.tinifycdn.com/" + path;
}In all your templates, such as in this Pug example, call the helper function to generate an asset URL.
html
head
script(src=assetUrl('/scripts/site.js'))
link(href=assetUrl('/styles/site.css') rel="stylesheet")
body
img(src=assetUrl('/images/header.jpg'))
