I have been utilizing AWS to host my personal blog for almost 3 years now. Originally my blog was hosted in WordPress and then I migrated to ghost. It’s been 2 years now in ghost and I thought of exploring a new hosting option which should be free, supports custom domain name and free SSL.
Jekyll is a ruby based static blog generator and it has an advantage of free hosting in GitHub. The letsencrypt SSL certificate is also provided by GitHub for my custom domain so i don’t have to worry about managing it.
I also created a separate website to showcase my open-source tools and I can use the same AWS instance for hosting it. It is a Django application which uses more memory/CPU, so i can run it in a dedicated instance instead of running the ghost and Django together.
One of the challenges in a Django application is hosting your static content. Django recommends using a proxy server like Nginx to serve its static content.
I use my nginx proxy to serve the static content. But due to performance reason , i started to explore the free CDN to serve my static content
Below is the nginx configuration snippet for mapping static content.
After doing some research I chose to utilize unpkg or jsdelivr for my site.
unpkg and jsdelivr are global CDN and they can be used to deliver any packages hosted in NPM
unpkg and jsdelivr both provides CDN for the content hosted in NPM. So first we should have the static content published in NPM.
NPM Package creation
1. Create the directory for adding packages for NPM
mkdir npm
mkdir npm/dist
cd npm
2. Create a package.json file for your package
npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install pkg` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (npm) vikki-tools
version: (1.0.0) 1.0.7
description: Libraries for https://tools.vikki.in
entry point: (index.js) dist/index.js
test command:
git repository: https://github.com/vignesh88/tools.git
keywords: vikki, tools
author: Vignesh Ragupathy
license: (ISC)
About to write to /home/vikki/npm/package.json:
{"name":"vikki-tools","version":"1.0.7","description":"Libraries for https://tools.vikki.in","main":"dist/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/vignesh88/tools.git"},"keywords":["vikki","tools"],"author":"Vignesh Ragupathy","license":"ISC","bugs":{"url":"https://github.com/vignesh88/tools/issues"},"homepage":"https://github.com/vignesh88/tools#readme"}
Is this OK? (yes) yes
3. Create a index.js
I added a javascript function that will be used to copy text to clipboard.
Now lets copy all our static content to the dist directory. I have various css,images,javascript that will be used in various app inside my django application.
Jsdelivr also provides the auto minified version of the CSS and Javascript from NPM. If you want to use minified version css and js, just add .min extension to the filename
Leave a Comment