Skip to main content

Make possible to use hashed static assets generated by tools like Gulp or Webpack

Project description


.. image::
:alt: Build Status

You care about the performance of your site, so you've configured the web server to cache all your assets for a long time. The most used way to bypass that cache when deploying a new version, is to add a hash of the assets to their names.
'scripts/home.js' --> 'scripts/home.1a23b.js'
'styles/home.css' --> 'styles/home.aef45.css'

The problem is, now your Python web app can't find the file unless you manually –and painstakingly— update all the URLs in the templates.

.. code:: html+jinja

<script src="{{ url_for('static', filename='scripts/home.js') }}></script>
<link rel="stylesheet" href="{{ url_for('static', filename='styles/home.css') }}</script>

Whit this library, there is no need for that. Just change your templates to:

.. code:: html+jinja

<script src="{{ 'scripts/home.js' | asset_url }}></script>
<link rel="stylesheet" href="{{ 'styles/home.css' | asset_url }}</script>

and use this code:

.. code:: python

from flask import Flask, render_template
from rev_assets import RevAssets

app = flask.Flask(__name__)

rev = RevAssets(reload=app.debug)
app.jinja_env.filters['asset_url'] = rev.asset_url

def index():
return render_template('index.html')

and it will work for every version of the assets that you build.

This works by reading the ``manifest.json`` generated by the revision tool (so don't forget to configure your task runner to make one).

You can continue to use the old method to link un-versioned assets, like ``favicon.ico`` and others like it.

Note that *this is not a Flask extension*, but a Python library. You can use it with any other framework. You can also have many instances of ``RevAssets`` linked to differents manifests.

Run the tests

We use some external dependencies, listed in ``requirements_tests.txt``::

$ pip install -r requirements-tests.txt
$ python develop

To run the tests in your current Python version do::

$ make test

To run them in every supported Python version do::

$ tox

Our test suite `runs continuously on Travis CI <>`_ with every update.


#. Check for `open issues <>`_ or open
a fresh issue to start a discussion around a feature idea or a bug.
#. Fork the `RevAssets repository on Github <>`_
to start making your changes.
#. Write a test which shows that the bug was fixed or that the feature works
as expected.
#. Send a pull request and bug the maintainer until it gets merged and published.
:) Make sure to add yourself to ``AUTHORS``.


:copyright: `Juan-Pablo Scaletti <>`_.
:license: BSD-3-Clause, see LICENSE.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rev-assets, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size rev_assets-1.0.3-py3-none-any.whl (5.8 kB) File type Wheel Python version 3.6 Upload date Hashes View
Filename, size rev-assets-1.0.3.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page