tet.static package

Static file serving with cache-busting support.

This module provides utilities for serving static files with automatic cache-busting via versioned URLs. When the application starts, a unique cache-breaker token is generated based on the current timestamp.

Features

  • Automatic cache-busting URLs for static assets

  • Graceful handling of old cache-breaker values (301 redirect)

  • Graceful handling of future cache-breaker values (503 retry)

Example

Setting up static files with cache-busting:

from tet.config import application_factory

@application_factory()
def main(config):
    config.include("tet.static")
    config.add_static_view_with_breaker(
        name="static/{breaker}",
        path="myapp:static",
    )
    config.scan()

In templates, use the versioned URL:

<link href="${request.static_url('myapp:static/style.css')}" rel="stylesheet">
tet.static.add_static_view_with_breaker(config, name, path, **kw)[source]

Add a static view with cache-busting support.

Parameters:
  • config – Pyramid Configurator

  • name – URL pattern with {breaker} placeholder

  • path – Asset specification for static files

  • kw – Additional arguments passed to add_static_view

tet.static.includeme(config)[source]

Pyramid includeme for static file cache-busting.

Adds config.set_cachebreaker() and config.add_static_view_with_breaker() directives.

tet.static.make_redirector(redirected_route)[source]

Create a view that redirects to the correct cache-breaker URL.

tet.static.set_cachebreaker(config, cachebreaker)[source]

Set a custom cache-breaker value.