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

Add compress skip patterns from settings #297

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

PetrDlouhy
Copy link

This combines both approaches to skipping files mentioned in #279:

  • Skip based on regexp patterns defined by WHITENOISE_SKIP_REGEX settings (--skip-regexp parameter)
  • Make the compressor class interchangable by WHITENOISE_COMPRESSOR_CLASS settings (--compressor-class parameter)

@LucidDan @merwok Please take a look at this. If everything is OK, I will add documentation for the new parameters/settings.

@PetrDlouhy PetrDlouhy changed the title (WIP) add compress skip patterns from settings Add compress skip patterns from settings Feb 2, 2022
@adamchainz
Copy link
Collaborator

I'd prefer not to add the regex setting when users can achieve the same in a few lines of code with a custom Compressor class, with more flexibility.

(Also your example for the regex strays a bit from the recommended setup. Sass/Less files should not be in the directory that Whitenoise serves - only compiled CSS files. So this makes me pause to think if the idea of skipping some files for compression is really valid, or it could be solved with better guidance for project structure.)

@PetrDlouhy
Copy link
Author

@adamchainz My complete regex list is:

WHITENOISE_SKIP_REGEXP = (
    r".*/src/",
    r".*\.scss$",
    r".*\.less$",
    r".*\.webm$",
    r".*map$",
    r".*\.md$",
    r"wagtailyoast.*",
    r"wagtailadmin.*",
    r"drf-yasg.*",
)

and while some of the scss might be possible to put outside static files dirs, others might be quite difficult. For example, django-scribbler contains static/scribbler/less/scribbler.less file. Also the folders like wagtailadmin are quite large and those files are needed only for admins, so the compression is not that essential.
Most of the files I want to exclude are coming from external applications, where it would be difficult to change project structure.

I think, that skipping compression of files by pattern is quite clear use-case and having to override the Compressor class would make unnecessary complexity in settings files.

But anyway, I can make separate MRs for those two things, so you can merge the WHITENOISE_COMPRESSOR_CLASS code.
I will have to look at my project structure more deeply and think through if it couldn't be in fact be reorganized or something.

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.

None yet

2 participants