miracle2k / django-assets

Django webassets integration.
BSD 2-Clause "Simplified" License
89 stars 79 forks source link

Cannot find version of gen/packed.%(version)s.js #90

Closed edevil closed 6 years ago

edevil commented 6 years ago

I'm using Django 1.11 with Whitenoise, and build my assets with:

./manage.py collectstatic
./manage.py assets build --manifest django

Built assets are correctly added to the staticfiles.json manifest.

IF I use the version of the file in the query string, the file is served but Whitenoise does not add far into the future cache headers:

✗ curl -I "http://localhost:8000/static/gen/packed.js?84fed0ca" 2>/dev/null |grep -i cache
Cache-Control: max-age=60, public

When I use the version placeholder:

output='gen/packed.%(version)s.js',

I get an error when trying to render the template:

webassets.exceptions.BundleError: Cannot find version of <Bundle output=gen/packed.%(version)s.js, filters=[<webassets.filter.jsmin.JSMin object at 0x106d45cf8>], contents=('js/vendor/jquery/jquery.min.js', 'js/vendor/bootstrap/bootstrap.min.js', 'js/main.js')>. There is no manifest which knows the version, and it cannot be determined dynamically, because: output target has a placeholder

Versions:

django-assets==0.12
webassets==0.12.1
edevil commented 6 years ago

The reason for not having the correct cache headers is because Whitenoise considers a file immutable when it has the hash in the filename, not the query string. So I really need to make django_assets correctly render the asset URL when the version placeholder is used with a Django manifest.

edevil commented 6 years ago

If I configure the manifest like this in the settings file:

ASSETS_MANIFEST = DjangoManifest()

The templates start to be rendered, however, there's a period added that's wrong:

<link rel="stylesheet" href="/static/gen/packed..f9a66270.css">
<script type="text/javascript" src="/static/gen/packed..84fed0ca.js"></script>

In the manifest they appear fine:

"gen/packed.js": "gen/packed.84fed0ca.js", "gen/packed.css": "gen/packed
.f9a66270.css"