Repository navigation
Invalidate HTTP cache by appending md5sum to static files - #71
Merged
Merged
Conversation
Static files are often cached. Changes to static files are then not immediately propagated to the clients resulting in broken pages until the cache expires or the user force-reloads the page. Since the HTTP cache is tied to the URL one way to invalidate cache is to change the URL when the file contents change. Add a Jinja2 filter 'static_file' that will generate a URL with the md5sum of the file appended as a query parameter. Appending a query parameter (the part after the '?') is not invasive. Using the 'static_file' filter is optional. Signed-off-by: Jan Heinemeyer <j.heinemeyer@pengutronix.de>
Put the "iterate over all static files" part into a helper method to simplify the plugin. Signed-off-by: Jan Heinemeyer <j.heinemeyer@pengutronix.de>
SmithChart
approved these changes
Aug 11, 2026
SmithChart
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution!
I've taken a moment to scroll over the documentation to see, if there would be a section where we could mention this new filter.
But honestly: The documentation currently mostly states how to develop flamingo and describes some selected internal concepts. There is no real section on how to create a good site using Flamingo.
So I guess can merge this without rewriting most of the documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Static files are often cached. Changes to static files are then not
immediately propagated to the clients resulting in broken pages until
the cache expires or the user force-reloads the page.
Since the HTTP cache is tied to the URL one way to invalidate cache is
to change the URL when the file contents change.
Add a Jinja2 filter 'static_file' that will generate a URL with the
md5sum of the file appended as a query parameter. Appending a query
parameter (the part after the '?') is not invasive.
Using the 'static_file' filter is optional. The old way of manually specifying the
hrefattribute still works.Usage Example:
<link rel="stylesheet" href="{{ static_file('theme/static/css/style.css') }}" type="text/css" />Will be rendered as
<link rel="stylesheet" href="/static/css/style.css?<md5sum>" type="text/css" />