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

Remove type="application/javascript" type from Analytics #6046

Closed
wants to merge 1 commit into from
Closed

Remove type="application/javascript" type from Analytics #6046

wants to merge 1 commit into from

Conversation

coliff
Copy link
Member

@coliff coliff commented Jun 19, 2019

This PR removes type="application/javascript" from Google Analytics snippet. If type was to be used it should be type="text/javascript", but the type isn't needed to be there anyway.

REF:

This PR removes ` type="application/javascript"` from Google Analytics snippet. If type was to be used it should be ` type="text/javascript"`, but the type isn't needed to be there anyway.

REF:
- https://google.github.io/styleguide/htmlcssguide.html#type_Attributes
- https://codeguide.co/#html-style-script
- https://developers.google.com/analytics/devguides/collection/analyticsjs/#alternative_async_tracking_snippet
@bep
Copy link
Member

bep commented Jun 19, 2019

Hugo uses type to identify minifier to use, so we cannot merge this. I'm not going into the discussion of what's the correct MIME type for JS, but the one built into Hugo is this:

https://github.com/gohugoio/hugo/blob/master/media/mediaType.go#L133

@coliff
Copy link
Member Author

coliff commented Jun 20, 2019

thanks for the reply @bep - fascinating. the link you gave with the MIME types uses MDN as the reference point (https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textjavascript) and it states clearly there:

Per the HTML specification, JavaScript files should always be served using the MIME type text/javascript. No other values are considered valid, and using any of those may result in scripts that do not load or run.

and there is a further note:

Note: Even though any given user agent may support any or all of these, you should only use text/javascript. It's the only MIME type guaranteed to work now and into the future.

But then at the top of that article it states that the Internet Assigned Numbers Authority (IANA) is responsible for all official MIME types, and you can find the most up-to-date and complete list at their Media Types page and there it states: text/javascript - OBSOLETED in favor of application/javascript. I've seen linters (like webhint) state that application/javascript is incorrect - so maybe that is wrong!

So I can see now why you don't want to get into a discussion about what the correct MIME type is! 😄

In any case, removing the type altogether doesn't appear to make a difference to minification with hugo --minify in my testing so is removing it not an option you'd consider?

@coliff coliff changed the title Remove incorrect type="application/javascript" type from Analytics Remove type="application/javascript" type from Analytics Jun 21, 2019
@XhmikosR
Copy link
Contributor

Note that there might be more cases like that (Hugo bundles?).

@coliff
Copy link
Member Author

coliff commented Jun 25, 2019

Yes, I think there are more cases of this -at least with the other Analytics snippets. What's your opinion on this subject @XhmikosR ? ...

Incidentally, the thing that flagged this to me was testing Hugo sites with http://webhint.io - but they've just merged a change to stop warning over the use of application/javascript - though they do recommend using text/javascript.

REF: webhintio/hint#2621

@XhmikosR
Copy link
Contributor

XhmikosR commented Jun 25, 2019

I just follow the specs personally.

But since Hugo needs the explicit type set for minification to work properly, I'm not sure what else can be done.

@stale
Copy link

stale bot commented Oct 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Oct 23, 2019
@bep
Copy link
Member

bep commented Oct 23, 2019

I can merge this if there is also a test that confirms that the minification is preserved. I assume it is, but it's good to have it confirmed.

@stale stale bot removed the Stale label Oct 23, 2019
@bep
Copy link
Member

bep commented Oct 23, 2019

I just follow the specs personally.

This think the spec in this case says that the type is optional for JS.

@XhmikosR
Copy link
Contributor

Yeah, it's optional, i.e. not an error, but a warning. https://validator.w3.org/nu/?doc=https%3A%2F%2Fgohugo.io%2F

@coliff
Copy link
Member Author

coliff commented Oct 23, 2019

I can merge this if there is also a test that confirms that the minification is preserved. I assume it is, but it's good to have it confirmed.

I can confirm for certain that minification is preserved without type="application/javascript" but don't have a test to prove it to go with this PR. On the Hugo site it uses a Google Tag Manager script without the type defined though (https://github.com/gohugoio/gohugoioTheme/blob/master/layouts/partials/gtag.html), and that minifies correctly.

@stale
Copy link

stale bot commented Feb 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Feb 20, 2020
@stale stale bot closed this Mar 21, 2020
@coliff coliff deleted the patch-3 branch January 19, 2022 06:22
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants