Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You have offline compression enabled but key is missing from offline manifest #169

Closed
markstahler opened this issue Dec 1, 2011 · 18 comments

Comments

@markstahler
Copy link

I am not sure what this issue is but I am using offline generation and this error occurs after using the compress management command and accessing the website. Should each of those css files have their own key?

My Settings:
COMPRESS_URL = STATIC_URL
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_OFFLINE = True
COMPRESS_OFFLINE_MANIFEST = "manifest.json" # Is created in CACHE directory
COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter','compressor.filters.cssmin.CSSMinFilter']
COMPRESS_YUI_BINARY = os.path.join(PROJECT_ROOT, 'bin/yui.sh')
COMPRESS_JS_FILTERS = ['compressor.filters.closure.ClosureCompilerFilter']
COMPRESS_CLOSURE_COMPILER_BINARY = os.path.join(PROJECT_ROOT, 'bin/closure.sh')
COMPRESS_CLOSURE_COMPILER_ARGUMENTS = "--language_in=ECMASCRIPT5"

COMPRESS_STORAGE = 'compressor.storage.GzipCompressorFileStorage' # DOES NOT WORK WTF

You have offline compression enabled but key "b68ba4d2116295c56138e439f1b03a03" is missing from offline manifest. You may need to run "python manage.py compress".

Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.3.1
Exception Type: OfflineGenerationError
Exception Value:
You have offline compression enabled but key "b68ba4d2116295c56138e439f1b03a03" is missing from offline manifest. You may need to run "python manage.py compress".
Exception Location: /srv/www/project/lib/python2.6/site-packages/compressor/templatetags/compress.py in render_offline, line 56

Variable    Value
forced  
False
self    
<compressor.templatetags.compress.CompressorNode object at 0x966764c>
compressor  
<compressor.js.JsCompressor object at 0x966732c>
key 
'b68ba4d2116295c56138e439f1b03a03'
offline_manifest    
{u'32e9172ad82f3b6d238cc7423a7f10c7': u'<link rel="stylesheet" href="/static/CACHE/css/a50381ce7ba9.css" type="text/css" media="screen" /><link rel="stylesheet" href="/static/CACHE/css/62afac347423.css" type="text/css" /><link rel="stylesheet" href="/static/CACHE/css/f336d54a5423.css" type="text/css" media="screen" /><link rel="stylesheet" href="/static/CACHE/css/5cf783d07673.css" type="text/css" />',
 u'b1bd8f68f96dfa53380b10881f8eb691': u'<script type="text/javascript" src="/static/CACHE/js/19522c6ee302.js"></script>',
 u'c6d6d2948d18188277e7a987c71e2bc3': u'<script type="text/javascript" src="/static/CACHE/js/90bda37980a5.js"></script>',
 u'dbe0b22545cd64193d8a875c3226b1ea': u'<script type="text/javascript" src="/static/CACHE/js/71056921eb77.js"></script>'}
@diox
Copy link
Member

diox commented Dec 1, 2011

What version of django_compressor are you using ?

@markstahler
Copy link
Author

Whatever is in PyPI. I will try upgrading to latest dev version. Thanks

@viotti
Copy link

viotti commented Dec 1, 2011

I had the same problem by mixing inline scripts with included files.

This was my template code.

{% compress js %}
    <script type="text/javascript">
    xhr_cidades = '{% url cidades_consulta %}';
    xhr_imoveis = '{% url imoveis_consulta %}';
    xhr_empresas = '{% url empresas_consulta %}';
    xhr_empreend = '{% url empreendimentos_consulta %}';
    </script>

    <script type="text/javascript" src="{{ STATIC_URL }}jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-ui/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-ui/jquery-ui-datepicker-pt-BR.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-ui/jquery-ui-combobox.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-meiomask-1.1.3.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-scrollto-1.4.2.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-dotimeout-1.0.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}base.js"></script>
{% endcompress %}

And this was the data that Django compressor was using to generate a manifest key.

['\n    <script type="text/javascript">\n        xhr_cidades = \'', '<django.template.defaulttags.URLNode object at 0x23cf1d0>',
 "';\n        xhr_imoveis = '", '<django.template.defaulttags.URLNode object at 0x23cf750>', "';\n        xhr_empresas = '",
 '<django.template.defaulttags.URLNode object at 0x23cf210>', "';\n        xhr_empreend = '",
 '<django.template.defaulttags.URLNode object at 0x23cf2d0>', '\';\n    </script>\n\n    <script type="text/javascript" src="',
 '<Variable Node: STATIC_URL>', 'jquery-1.6.1.min.js"></script>\n    <script type="text/javascript" src="', '<Variable Node:
 STATIC_URL>', 'jquery-ui/jquery-ui-1.8.13.custom.min.js"></script>\n    <script type="text/javascript" src="', '<Variable
 Node: STATIC_URL>', 'jquery-ui/jquery-ui-datepicker-pt-BR.min.js"></script>\n    <script type="text/javascript" src="',
 '<Variable Node: STATIC_URL>', 'jquery-ui/jquery-ui-combobox.min.js"></script>\n    <script type="text/javascript" src="',
 '<Variable Node: STATIC_URL>', 'jquery-meiomask-1.1.3.min.js"></script>\n    <script type="text/javascript" src="',
 '<Variable Node: STATIC_URL>', 'jquery-scrollto-1.4.2.min.js"></script>\n    <script type="text/javascript" src="', '<Variable
 Node: STATIC_URL>', 'base.js"></script>\n']

The key is a digest of the string representation of the list of nodes inside the {% compress %} block. If that data varies each time the block is parsed (see the 0x23cf750 address on the URLNode above), a page load will always generate a distinct key from what you have stored in your manifest file.

In my case, removing the inline code from the {% compress %} block resolved the issue.

You can trace the data and digest in the get_hexdigest function of compressor.cache. Look for clues in your standard output/web server error log.

Hope it helps,

@diox
Copy link
Member

diox commented Dec 1, 2011

It should be fixed in development version, thanks to the fix that went in #154

@markstahler
Copy link
Author

Looks like the problem was a script include inside an inline block. This was on latest dev version.Thanks @viotti

{% compress js inline %}
<script type="text/javascript" src="/static/js/pages/calculator.js"></script>

@pelme
Copy link
Contributor

pelme commented Jan 14, 2012

This issue should probably be closed, as noted earlier here, it is a duplicate of #154.

@rubenjimenez
Copy link

Hi, i'm suffering this issue. My settings.py looks like this:

### COMPRESSION - django_compressor
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_PARSER = 'compressor.parser.LxmlParser'
COMPRESS_CSS_FILTERS = [
    'compressor.filters.css_default.CssAbsoluteFilter',
    'compressor.filters.cssmin.CSSMinFilter',
    ]
COMPRESS_JS_FILTERS = [
    'compressor.filters.closure.ClosureCompilerFilter',
]

COMPRESS_CLOSURE_COMPILER_BINARY = 'java -jar /path/to/compiler.jar'

All works right except by inline js code present in .html file. I have several css/js external files linked from my .html. All these are well compressed with {% compress css/js %}, but when i try to compress all the js code printed in .html file (code between <script></script> labels) i get this error.

"OfflineGenerationError at /
You have offline compression enabled but key "b7126bf66f8e06bde131d96c54be3a47" is missing from offline manifest. You may need to run "python manage.py compress"."

Any tip to solve this?

@diox
Copy link
Member

diox commented Jul 9, 2012

rubenjimenez: please try the development version. If that doesn't fix your problem, open up a new bug, with the following info:

  • Does it work without enabling offline compression?
  • Minimal set of templates used to reproduce the problem

@rubenjimenez
Copy link

I prove development version and i'm still getting the same error. It only occurs in offline compression and it always appears with any js inline code.

I'm trying with {% compress js %} and not with {% compress js inline %} (which also fails).

If you need more information, don't hesitate to ask for it.

@dasloss
Copy link

dasloss commented Jun 20, 2013

same issue with development branch

@dasloss
Copy link

dasloss commented Jun 20, 2013

Still having issues with this. It appears that even in the dev branch, using {{ STATIC_URL }}, the hex generation process is generating new hexes that do not make any sense or correspond to the hexes saved in manifest.json.

@dasloss
Copy link

dasloss commented Jun 20, 2013

Solution: dont have compress js span a block. Eg, use compress once in the master template and once in the the templates that each inherit. Downside: two http requests for css and js each, instead of one. Can be reduced to one by moving the master js/css to be in all the templates.

Would be nice if we didnt have to choose between DRY in templates and reducing http requests:)

@altryne
Copy link

altryne commented Nov 13, 2013

Have the same thing happen. Don't have any inline code in compress, and the key that reports missing is in fact exists in manifest.json
Really don't know what the hell is happening, anyone else still has this? All the other comments on this are from a year ago

@diox
Copy link
Member

diox commented Nov 13, 2013

@altryne : it could be a permissions problem, verify that the webserver / django process has the rights to read the manifest. Can't help much more without more details.

@altryne
Copy link

altryne commented Nov 13, 2013

Turns out it was a Django thing with a 500 page. With compression offline, django tried to render the 500 page without context, which in itself created the 500 error.

This really helped:
http://chriskief.com/2013/09/18/django-compressor-offlinegenerationerror-and-500-html-handler500/

@programmdesign
Copy link
Contributor

Hi everyone, the link to chriskief.com was helplful. However, it did not solve the problem for me. It turned out that I had django template vars like "{{myvar}}" in my javascripts. I forgot to add them to COMPRESS_OFFLINE_CONTEXT and hence I got the missing key error. Once i took all my javascripts with template variables out of the compressor, everything worked fine again. Before I got a 500 error which did not display the standard django error but the Apache "misconfiguration page". I am not sure yet, if only missing definitions in COMPRESS_OFFLINE_CONTEXT are the problem or if also {% url ... %} causes this issue.

@morenoh149
Copy link

I'm seeing this in my deployment. I use compress like so

{% compress css %}
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap-social.css' %}">
<link rel="stylesheet" type="text/css" href="{% sass_src 'css/base.scss' %}">
{% endcompress %}

could it be that compress cannot process the sass_src tag?

@amiknyc
Copy link

amiknyc commented Sep 16, 2021

I'm seeing this in my deployment. I use compress like so

{% compress css %}
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap-social.css' %}">
<link rel="stylesheet" type="text/css" href="{% sass_src 'css/base.scss' %}">
{% endcompress %}

could it be that compress cannot process the sass_src tag?

I ran into this issue and it has to do with the use of the "bootstrap.min.css" - if you use the non-minified version of bootstrap it should work.

Basically, compressor is trying to minify a file that is... already minified. Thus it throws an error.

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

No branches or pull requests

10 participants