My code with django-compressor works on my local machine with DEBUG=True or False, but when I push to production, which is a Windows Server 2019 served by IIS, then it only works with DEBUG=True. If I set to False, then I get this error: OfflineGenerationError: You have offline compression enabled but key is missing from offline manifest.

I have looked at many different other posts regarding this same issue but none solve it for me so far. Here are my details:

I am using pipenv
[requires]
python_version = "3.8"

[packages]
django = "3.1.2"
django-compressor = "2.4"
whitenoise = "5.2.0" {extras = ["brotli"], version = "1.0.9"}
wfastcgi = "3.0.0"

Production Details

Windows Server 2019
IIS for 2019

settings.py

INSTALLED_APPS = [
    ...
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'compressor',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    ...
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/assets/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'assets')
]

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder', 
)

COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage"

COMPRESS_FILTERS = {
    "css": [
        "compressor.filters.css_default.CssAbsoluteFilter",
        "compressor.filters.cssmin.rCSSMinFilter",
    ],
    "js": ["compressor.filters.jsmin.JSMinFilter"],
}

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

WHITENOISE_MAX_AGE = 31536000 if not DEBUG else 0 # 1 year

COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True

Any thoughts on how I can debug why it won't work with DEBUG = False, but works in all other 3 situations.

One more thing I will throw out, I don't have SSL setup yet on production, could this be the cause of it not working? I thought I read somewhere of something only delivering cached something if it was an SSL call.

1

There are 1 answers

0
Douglas T On

Okay, the solution to my problem is laughable, but I finally figured it out. No wonder no other solutions seemed to help me.

I had an image file with an uppercase letter, like this: "Logo.svg", but I was calling it like this:

<img src="{% static 'images/logo.svg' %}">

I renamed my file to "logo.svg" on development, but apparently git commit did not get that change and did not change it on production. So it worked locally, but on production when collectstatic was run then it created a manifest for Logo.svg (uppercase letter) and the site was looking for logo.svg (lowercase). The error message of OfflineGenerationError was not that helpful in figuring that out. Anyway, renamed it to lowercase on the server and it is running with both whitenoise and django-compressor.

I hope this can help someone else. What gave me the clue was I finally took off django-compressor and just used white-noise and that gave me the manifest error.