Final thoughts on static files
Some tips
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the Serverless Django with Zappa course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to Serverless Django with Zappa, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
[00:00 - 00:09] Now that we've gone through the configuration for both white noise and S3, I wanted to share some final thoughts on static files. So what should you choose, white noise or S3?
[00:10 - 00:15] Actually, either way is fine. You really should pick the option that best meets your needs.
[00:16 - 00:28] We've gone through the pros and cons of each, and you can decide for yourself and for your project, which is the best path to take. But remember to always run collect static if you make changes to your files.
[00:29 - 00:35] One thing that's interesting about static files is caching. Caching tells the browsers to keep a file around.
[00:36 - 00:50] It also tells any middle systems between your AWS Lambda project and the client's browsers to keep the file around. This helps lower costs because the browser then keeps a copy of those files and doesn't have to go back to your AWS Lambda to get it.
[00:51 - 01:05] In fact, for some files that don't change very much, maybe your logo, you could configure the static file to be cached for a year or more. However, the downside of this system is that detecting changes is hard.
[01:06 - 01:15] So that when your logo does change, you have to tell all these systems that have kept copies of your logo that you have a new one now. And that is a difficult problem to solve.
[01:16 - 01:25] One way of approaching this is to use a content delivery network or a CDN. A CDN is a service with geographically distributed groups of servers.
[01:26 - 01:34] The goal is to provide a fast delivery of files to clients all over the world. And it works pretty well, but many CDNs charge for these services.
[01:35 - 01:45] I will note, usually you don't need these for small sites. So unless you really need fast delivery of files, I would skip this step until you're ready for it.
[01:46 - 01:55] While that's about it for static files, the next module we're going to learn how to use custom domain names to make our URLs much easier to read and more user-friendly.