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

Skip compression of already compressed files based on saved file hashes #296

Closed
wants to merge 1 commit into from

Conversation

PetrDlouhy
Copy link

This is better approach to fix #279 than MR #295.
It saves hashes of all files and compresses only files, their hash changed.

@adamchainz
Copy link
Collaborator

Can’t this be done with an existence check rather than an extra file of metadata? e.g. if trying to compress app.abc123.js, avoid gizp compressing if app.abc123.js.gz exists, and likewise if .br exists.

@PetrDlouhy
Copy link
Author

@adamchainz It would be needed to regenerate the compressed file if the app.abc123.js changes.
Maybe it could be determined by the modification dates of the files, but I am not sure, if that mechanism couldn't fail in some cases. I just felt, that the MD5 sums are more reliable.

@adamchainz
Copy link
Collaborator

The hash abc123 in the filename is already an MD5 hash. I'm not sure you've followed what Whitenoise is already doing?

@PetrDlouhy
Copy link
Author

In my project, I see compressed versions for files with hash as well as files without hash. For example for base.css the manage.py collecstatic creates all these files:

base.css
base.css.br
base.css.gz
base.1f418065fc2c.css
base.1f418065fc2c.css.br
base.1f418065fc2c.css.gz

So if I haven't overlooked something, it means, that the problem is still valid for half of the files.

@adamchainz
Copy link
Collaborator

Right - those unhashed files are “left over” by ManifestStaticFilesStorage. I’m not sure it’s even sensible to leave those files around - in normal use of staticfiles they won't be referenced. Whitenoise has the WHITENOISE_KEEP_ONLY_HASHED_FILES setting to remove them, which I've turned on for many projects as a nice boost. I am considering making that the default, or even proposing it for Django.

@PetrDlouhy
Copy link
Author

@adamchainz OK, thank you for explaining. That is very neat option.
Then skipping compression of already compressed files should be as easy as this: #347

@PetrDlouhy PetrDlouhy closed this Feb 2, 2022
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

Successfully merging this pull request may close these issues.

Slow compression with many files - add skip patterns settings
2 participants