Skip to content

Invalidate HTTP cache by appending md5sum to static files - #71

Merged
SmithChart merged 2 commits into
pengutronix:masterfrom
janheini:hash-static-files
Aug 11, 2026
Merged

SmithChart merged 2 commits into
pengutronix:masterfrom
janheini:hash-static-files

Conversation

@janheini

Copy link
Copy Markdown
Member

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 href attribute 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" />

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>
@janheini
janheini requested a review from SmithChart August 11, 2026 05:47

@SmithChart SmithChart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SmithChart
SmithChart merged commit 5b7190b into pengutronix:master Aug 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants