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

add support for type=module & attr nomodule #1006

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

dmlb
Copy link

@dmlb dmlb commented Jul 16, 2020

Add support for the attribute 'nomodule' on <script> tags inside JsCompressor
Add support for output mode 'module' for script tag with <script type="module"> in base.py and supporting HTML Template files
Fix 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

Copy link
Contributor

@karyon karyon left a 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]] %}
Copy link
Contributor

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?

Copy link
Author

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.
Copy link
Contributor

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:
Copy link
Contributor

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 %}
Copy link
Contributor

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.

@karyon
Copy link
Contributor

karyon commented Jan 1, 2021

@diox do you have any comment on module support in general?

@diox
Copy link
Member

diox commented Jan 2, 2021

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.

@dmlb
Copy link
Author

dmlb commented Jan 7, 2021

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 :)

@dmlb dmlb force-pushed the support-type-module-more-script-attributes branch from 0f11e70 to 51153dc Compare December 16, 2021 20:57
@dmlb dmlb force-pushed the support-type-module-more-script-attributes branch from 51153dc to cc1b04f Compare December 16, 2021 21:19
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.

None yet

3 participants