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

preload output overrides normal output later #961

Open
iamareebjamal opened this issue Nov 26, 2019 · 4 comments
Open

preload output overrides normal output later #961

iamareebjamal opened this issue Nov 26, 2019 · 4 comments
Labels

Comments

@iamareebjamal
Copy link

Let's say you wrote this to create a link preload tag:

{% compress js preload %}
  <script ...a.js" />
  <script ...b.js" />
  <script ...c.js" />
{% endcompress %}

It will produce this:

<link rel="preload" href="..." />

Now, when you want the actual script and you write it without preload attribute,

{% compress js %}
  <script ...a.js" />
  <script ...b.js" />
  <script ...c.js" />
{% endcompress %}

It still emits link preload tag.

So,

Expected:
<script src="shamalamadingdong.js"></script>

Actual:
<link rel="preload" href="shamalamadingdong.js" as="script" />

@karyon
Copy link
Contributor

karyon commented Dec 23, 2019

thanks for the report. the preload feature was implemented in #951. it's not immediately obvious to me what the problem might be. The PR doesn't even add code that's specific to the preload feature, so you might be able to repro this even with the file or inline output modes... (it's just that you wouldn't have any reason to do that with those modes, whereas the preload tag is more or less designed to be used twice...)

anyway, we take PRs! :)

@karyon karyon added the bug label Dec 23, 2019
@VivienGiraud
Copy link

I have the same behaviour here. Though I was doing it wrong. preload system is a bit young, but could be an interesting feature for sure !

@jsumnerPhD
Copy link
Contributor

Hi @VivienGiraud and @iamareebjamal - I just tested wrapping multiple scripts in preload and then the normal compress and it seems to work fine.

But... it unfortunately all breaks down if COMPRESS_OFFLINE is True. The cache manifest is updated when the first tag is encountered (in this case with preload) and the file hash is then always mapped to the same HTML output. @karyon's intuition seems correct: any set of tags would have this behaviour (but the behaviour would be correct in any other context).

It looks like this can be fixed by updating how the cache key is generated by e.g. prepending the mode. I will put together a PR to get the discussion rolling.

@jsumnerPhD
Copy link
Contributor

@karyon - I added an extra commit to #1033 which fixes this problem. I don't love the solution as the node object passed by the django engine and the node object passed by the jinja2 engine seem to be different and I have to treat each separately. It feels a bit brittle.

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