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

Not serving compressed files #422

Closed
andyp05 opened this issue Oct 8, 2022 · 9 comments
Closed

Not serving compressed files #422

andyp05 opened this issue Oct 8, 2022 · 9 comments

Comments

@andyp05
Copy link

andyp05 commented Oct 8, 2022

Python Version

3.10.7

Django Version

4.1

Package Version

6.2.0

Description

Using Django on IIS and whitenoise is serving the css and js fine in uncompressed format. I have the settings for middleware

'whitenoise.middleware.WhiteNoiseMiddleware',

and

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

setup as documented. I have run collectstatic and the files are collected, the gz and br variants are created and the manifest json is created.

When a static file is requested, whitenoise will return the plain/uncompressed js or css file. I can compress it using the cloudflare CDN, but I would like to understand why the brotli file is not sent from the origin. All built-in IIS compression is disabled. But if I enable it, I get the IIS compressed file (different file-size then the .br file on disk).

@adamchainz
Copy link
Collaborator

Is the Accept-Encoding header being sent correctly? How are you testing?

@andyp05
Copy link
Author

andyp05 commented Oct 8, 2022

Accept-Encoding is set to: gzip, deflate, br
Using Postman app to send request for a css file.
In this case, I now have it return gzip.

Edited Accept-Encoding to just br
IIS sends uncompressed file. Confirmed by looking at bytes downloaded.

The test.css.br file is in my static folder.

@adamchainz
Copy link
Collaborator

Browsers only use Brotli compression over HTTPS, it may be that IIS follows this. Are you testing over HTTPS?

@andyp05
Copy link
Author

andyp05 commented Oct 9, 2022

Yes it is over HTTPS. I tested and pulled a css file from another site and it came in as br
Whitenoise must be sending the file because I have Static File Handling in IIS turned off and the css file I get has the MD5 hash in the filename.

@adamchainz
Copy link
Collaborator

I'm afraid I can't help you further here, unless you can provide a simple reproduction (I've never used IIS, maybe you can give e.g. Docker commands to run it, along with a sample project).

But mostly I think you'll need to roll your sleeves up and debug each stage, maybe add print statements inside your app/whitenoise to see what headers are actually getting through, where Whitenoise is deciding not to send brotli, etc.

@andyp05
Copy link
Author

andyp05 commented Oct 10, 2022

Will do.
I will post any solution in case this comes up again for another user.
Thanks

@andyp05
Copy link
Author

andyp05 commented Oct 10, 2022

I am using Cloudflare CDN and they only request gzip from origin. I turned off proxy and put in development mode to test and the request is still gzip. That surprised me, but this issue is resolved.
Thanks for your help.

@andyp05 andyp05 closed this as completed Oct 10, 2022
@adamchainz
Copy link
Collaborator

Problem solved then!

@andyp05
Copy link
Author

andyp05 commented Feb 1, 2023

I am using Cloudflare CDN and they only request gzip from origin. I turned off proxy and put in development mode to test and the request is still gzip. That surprised me, but this issue is resolved.
Thanks for your help.

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

2 participants