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

compress preload does not works when COMPRESS_ENABLED isn't enabled #987

Open
VivienGiraud opened this issue Jan 20, 2020 · 3 comments
Open
Labels

Comments

@VivienGiraud
Copy link

When COMPRESS_ENABLED is set to False the following will occur:

  {% compress js preload %}
  <script src="{% static 'js/base/jquery-3.3.1.min.js' %}"></script>
  {% endcompress %}

Will be outputed like this :

<script src="localhost:8000/js/base/jquery-3.3.1.min.js"></script>

And so it will be executed instead of just being preloaded.
When COMPRESS_ENABLED is set to True the output is correct :

<link href="localhost:8000/js/base/jquery-3.3.1.min.js" rel="preload" as="script">

I think the default behaviour is not correct and even if compression isn't enabled the preload should be made.

@jsumnerPhD
Copy link
Contributor

Salut Vivien,

I agree with you that the default behaviour for COMPRESS_ENABLED = False doesn’t make much sense. Support for the preload directive was achieved by simply changing the template used in the existing compressor workflow… a rather straightforward solution and it looks like it will need to be revisited.

If we want proper preload tags generated regardless of the state of COMPRESS_ENABLED, I think we will need to parse the css/js of the block and only generate preload tags where appropriate, i.e. not for any inline styles or scripts. The get_original_content method seems like a good place to add this extra bit of logic.

@karyon - I don't mind taking a stab at fixing this bug, but before I dive into it, do you have any comments?

Cheers

@VivienGiraud
Copy link
Author

Salut cousin @jsumnerPhD !

Thanks for being part of it!
I don't have that much time to be useful but if I can I will!

Cheers!

@natevw
Copy link

natevw commented Sep 16, 2021

The same is true of the inline option. If I need a set of scripts/stylesheets inline for some reason (e.g. generating some standalone HTML) then that should happen regardless of whether the compression (or debug mode) is happening or not.

I think both the preload and inline options are analogous to the existing compilation step, where I can include LESS or Typescript or whatever and it gets converted even when it's not actually compressed. Otherwise things tend to simply break when DEBUG is on.

(In some ways even the block_name has some call to always be in effect, but if so that should get its own issue and discussion thread — hopefully its okay to lump the inline in here with preload though since they're a lot more similar.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants