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 support for type=module & attr nomodule #1006
base: develop
Are you sure you want to change the base?
add support for type=module & attr nomodule #1006
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay.
Since we modify the filename, and the filename is the modulename, the compressed module can't be imported by other modules anymore (which might be fine depending on the use case). I think this should be mentioned in the documentation.
Also, modules can't be concatenated, so this option will break if a user puts a second file into the really makes sense only for a single file in the compress tag. This should also be documented. A fix might be to disable concatenation if any of the contained files is a module, but I'd rather keep it simple.
So, I appreciate this feature to enable a specific limited use case, but it should be documented that this is really just a specific limited use case, and no support for modules in general.
@@ -6,7 +6,7 @@ Usage | |||
.. code-block:: django | |||
|
|||
{% load compress %} | |||
{% compress <js/css> [<file/inline/preload> [block_name]] %} | |||
{% compress <js/css> [<file/inline/preload/nomodule> [block_name]] %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't that be module
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nomodule
is an attribute itself, but module
is a type
attribute option - they have a relationship but they are not the same
this is for how the library strips all attributes
|
||
ES5 nomodule & ES6 type="module" | ||
|
||
Adding the ``nomodule`` attribute will generate be passed attribute to the script tag for the compressed resource in the template. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sentence didn't quite parse for me :)
ES5 nomodule & ES6 type="module" | ||
|
||
Adding the ``nomodule`` attribute will generate be passed attribute to the script tag for the compressed resource in the template. | ||
Adding the ``module`` parameter will generate the script tag with type="module" for the compressed resource in the template: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest clarifying that nomodule
needs to go into the script html tag, and module
needs to go into the compress templatetag.
<script nomodule async src="static/js/es5.js"></script> | ||
{% endcompress %} | ||
|
||
{% compress js module %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better if this supported the type="module"
syntax instead of the additional templatetag parameter. Then i would also worry less if it still worked properly with COMPRESS_ENABLED = False.
@diox do you have any comment on module support in general? |
I am not sure it's worth doing. Modules are difficult to support properly for compressor. As you pointed out, the filename needs to be known in advance and you likely don't want to use compressor on them in the first place - you probably don't want concatenating the scripts either. I just don't see the point of adding complexity for it in compressor. |
yes, it is for very small specific use case and was not able to solve for proper module splitting :) |
0f11e70
to
51153dc
Compare
51153dc
to
cc1b04f
Compare
Add support for the attribute 'nomodule' on
<script>
tags insideJsCompressor
Add support for output mode 'module' for script tag with
<script type="module">
inbase.py
and supporting HTML Template filesFix error message for 'preload' output mode and add new 'module' output mode
Add test for module output mode
Add to attributes test for nomodule attribute
potentially closes:
#1001