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

Unable to change script type to import JS dependency into Grails-app #323

Closed
azdurov opened this issue Feb 1, 2023 · 2 comments
Closed

Comments

@azdurov
Copy link

azdurov commented Feb 1, 2023

I am trying to connect the JS library as a module in Grails application. For this, I use the following format in the GSP:
<asset:javascript src="myLibrary.js" type="module"/>

The "type" attribute is the usual one for the "script" tag. W3 specification

The error is on the following line:

outPw << '<script type="text/javascript" src="' << assetPath(src: src, useManifest: useManifest) << queryString << '" ' << paramsToHtmlAttr(outputAttrs) << '></script>' << endOfLine

The "type" attribute with the value "text/javascript" is hard-coded into the string.

It is necessary to add a check for the presence of the attribute "type" in the "attrs" list: if (!attrs.containsKey('type'))
And only in this case add "type="text/javascript"" to the generated string.

Example result code:
outPw << '<script ' << (!attrs.containsKey('type') ? 'type="text/javascript"' : '') << ' src="' << assetPath(src: src, useManifest: useManifest) << queryString << '" ' << paramsToHtmlAttr(outputAttrs) << '></script>' << endOfLine

@azdurov
Copy link
Author

azdurov commented May 3, 2023

@davydotcom , could you take a look? There is a proposal for a fix here.

davydotcom added a commit that referenced this issue Jul 25, 2024
@davydotcom
Copy link
Contributor

@azdurov fixing for next release

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

No branches or pull requests

2 participants