Make Your Static Files Production Ready with Flask-Static-Digest
In this video we'll go over a Flask extension that md5 tags and gzips your static files. We'll cover both the why and the how.
If you prefer reading instead of watching videos the README file on the Flask-Static-Digest repo covers everything about the project, although the video below covers more ground on the “why” aspect of this extension and how cache busting works in general. It also demos using the extension.
In my opinion this is an extension that you’ll want to use in every single Flask application that you deploy. I’ve been doing something similar to what this extension does for years with Flask.
The end result is it will allow you to cache your static files forever with a web server such as nginx. It also gzips your files at maximum compression. When you combine both things together it will save you money on hosting and make a very noticeable improvement on page load speeds for your users.
How This Extension Helps Reduce Page Load Speeds and a Demo of How It Works
Timestamped Table of Contents
- 0:15 – It’s not a competitor to Webpack and other asset build tools
- 1:10 – This extension completely replaces my other Flask-Webpack extension
- 2:03 – A quick look at an example app’s HTML source and Jinja 2 templates
- 3:36 – Why you’ll want to use this in every Flask project
- 4:38 – It’s meant to run in production but you can use it in development too
- 4:54 – Running the new flask digest compile command
- 6:17 – Viewing the digested files that the compile command generated
- 7:32 – Viewing the page source with digested files
- 7:59 – Briefly talking about how md5 hashing works
- 8:52 – This extension lets you efficiently cache your static files
- 13:48 – Gzipping your static files can shrink them by 10x or 20x
- 16:51 – Going over how this extension works
- 17:14 – Looking at the cache manifest file this extension creates
- 18:20 – Using the new static_url_for template helper
- 19:59 – Quickly looking at the source code for static_url_for
- 22:07 – This extension won’t make your site slower, it’ll make it faster!
- 22:34 – Other forms of cache busting and why md5 tagging files is really good
- 23:49 – Ignoring certain file types or skipping the gzip process
- 24:31 – Git ignoring the md5 tagged and gzipped files
- 24:58 – Cleaning your digested files with this extension
- 26:01 – Automatically digesting your static files in a Dockerfile
Are you going to be using this extension or have any questions? Let me know below.