Skip to content

Disable sourcemap (CSS) generation in production environment #185

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

Closed
wants to merge 1 commit into from
Closed

Disable sourcemap (CSS) generation in production environment #185

wants to merge 1 commit into from

Conversation

ivanionut
Copy link

modifies the SassProcessor to set sourcemap_filename to None in production environments. This optimization reduces file size, improves performance, and eliminates unnecessary debug information in production builds. Sourcemaps remain fully functional in development mode.

@jrief
Copy link
Owner

jrief commented Mar 25, 2025

There should be an explicit Django settings named SASS_PROCESSOR_CREATE_SOURCEMAP, it can default to the same value as DEBUG but users must have the possibility to override it.

Documentation is missing.

Tests are missing.

@ivanionut
Copy link
Author

hi @jrief
I thought it was an oversight, for two reasons:

  1. documentation already exists with:

During development, a sourcemap is generated along side with the compiled *.css file. This allows to debug style sheet errors much easier.

  1. similar logic already exists in the code:

if not settings.DEBUG:
options.append('--no-map')

@jrief
Copy link
Owner

jrief commented Mar 25, 2025

Well, then why did you create a pull request?

In production, CSS files are pregenerated anyway using ./manage.py compilescss and by specifying that option, sourcemaps are not generated.

In development CSS files und sourcemaps are generated on the fly. Does it really make sense to disable sourcemaps during development?

@ivanionut
Copy link
Author

In production, CSS files are pregenerated anyway using ./manage.py compilescss and by specifying that option, sourcemaps are not generated.

Using ./manage.py compilescss correctly compiles CSS files without the sourcemap.
But if I DON'T use the compilescss command and set DEBUG=False and SASS_PROCESSOR_ENABLED=True, then the CSS files are generated WITH the sourcemap. This should be considered incorrect behavior.

In development CSS files und sourcemaps are generated on the fly. Does it really make sense to disable sourcemaps during development?

No, absolutely not. I don't need to change the behavior in the development environment.

@jrief
Copy link
Owner

jrief commented Mar 25, 2025

If I understand you correctly, in production you want to generate the CSS files on the fly and then serve them through the Django's staticfiles app? This means that every time a CSS file is loaded, Django has to iterate over all static-folders from all apps and look for the proper file. Maybe I misunderstood your intention, but if you try to do what I just wrote, I would say that this is a big no-no.

@ivanionut
Copy link
Author

Even now, if you set DEBUG=False and SASS_PROCESSOR_ENABLED=True, SCSS files are compiled on the fly in production.

@jrief
Copy link
Owner

jrief commented Mar 25, 2025

Even now, if you set DEBUG=False and SASS_PROCESSOR_ENABLED=True, SCSS files are compiled on the fly in production.

I would strongly recommend against such a setting.

@ivanionut ivanionut closed this Mar 25, 2025
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.

2 participants