Skip to content

Add support for rel=preload - #951

Merged
karyon merged 2 commits into
django-compressor:developfrom
jsumnerPhD:develop
Aug 18, 2019
Merged

karyon merged 2 commits into
django-compressor:developfrom
jsumnerPhD:develop

Conversation

@jsumnerPhD

Copy link
Copy Markdown
Contributor

Hi all,

This is a small change to simplify generating the <link rel="preload"> tag with the correct hash for a given css or js file.

Tests and docs included.

Cheers!

@jsumnerPhD

Copy link
Copy Markdown
Contributor Author

Updated the test suite for #931 and #926.

Hard-coded hashes updated by working through failing unit tests one by one... maybe there was an easier way?

Cheers!

@karyon

karyon commented Aug 5, 2019

Copy link
Copy Markdown
Contributor

I cherry-picked the second commit into #952 and merged that. thanks!

regarding the first commit, i don't fully understand the matter, but it seems there are other attributes besides preload that could be supported, see #690. if that's the case, it seems like your solution does not scale to multiple attributes because you'd need one OUTPUT_MODE per attribute combination, is that correct?

@jsumnerPhD

Copy link
Copy Markdown
Contributor Author

Hi karyon,

rel=preload is more like a directive than an attribute: it is intended to give the browser a heads up that a resource will be needed, so start loading it now. The purpose of adding a preload output mode to django-compressor is to be able to take advantage of this directive for our own cached resources.

With this additional output mode, django-compressor can now generate an inline compressed script/stylesheet, an external compressed file, or simply the preload tag (which does the same thing as file but returns the preload tag instead of the script/link tag). It really is unrelated to the problem of extra attributes.

My workflow with this version of django-compressor uses preload mode in the head and then calls the actual scripts as needed. preload really just takes care of generating the correct filename in the tag: instead of <script src="..."> in the head, it will output <link rel="preload" as="script" href="...">.

<head>
...
{% compress js preload %}
<script src="{% static 'website/js/index.min.js' %}"></script>
{% endcompress %}
...
</head>

<body>
...
{% compress js %}
<script src="{% static 'website/js/index.min.js' %}"></script>
{% endcompress %}
...
</body>

Cheers!

@karyon
karyon merged commit 9e43060 into django-compressor:develop Aug 18, 2019
@karyon

karyon commented Aug 18, 2019

Copy link
Copy Markdown
Contributor

thanks!

@timonweb

Copy link
Copy Markdown

Any idea when this is going to be released?

@karyon

karyon commented Oct 10, 2019

Copy link
Copy Markdown
Contributor

no, sorry.

(fwiw, it's really really easy to put a specific commit of a git repository into your requirements.txt, try it! :D there's no additional testing or the like done on releases, so there's little downside for you.)

@diox

diox commented Oct 12, 2019

Copy link
Copy Markdown
Member

I'm planning to do a release later this month. Please use the develop branch in the meantime.

@VivienGiraud

Copy link
Copy Markdown

Nice, but it seems that it's not working when COMPRESS_ENABLED is False, then it juste leaves the js files ready to be executed :/

@karyon

karyon commented Jan 17, 2020

Copy link
Copy Markdown
Contributor

@VivienGiraud can you please open a new issue with the actual and expected behavior?

@VivienGiraud

Copy link
Copy Markdown

@karyon Thanks, here is the link : #987

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.

5 participants