3

From the beginning of december 17, W3C XHTML started to point out this error:

The type attribute is unnecessary for JavaScript resources.

The above warning is generated inside Joomla script itself to call modules or jQuery, CSS, etc. and is not written in any Joomla file. Probably is related the way Joomla call scripts in core files. This problem also appears in WordPress, but there is a workaround. In Joomla I removed all the modules, the warnings decrease, but still there. I tested with another template, updated Joomla version to 3.8.3 and no solution.

1
  • I'm voting to close this question as off-topic because it's not question or discussion but change proposal and should be at github issues
    – Alexandr
    Jan 9, 2018 at 5:17

3 Answers 3

2

Joomla adds this attribute by default when a javascript is added but the type parameter is not specified. You can see this in the addScript function at libraries\src\Document\Document.php.

Whilst you could write a plugin to override this output, it seems a pointless endeavour. A warning is not the same as an error. In this case, the code is still valid, merely with some unnecessary bulk (this is because the HTML5 specification states that the default type value of <script> is already "text/javascript").

I'd assume future versions of Joomla are likely to remove that tag as it serves no real purpose any more - users on non-HTML5 browsers are going to be practically none-existant.

Whilst you should always use a validator, fixing every error and warning can be a mistake. Review them, and make sure you understand them. Fix any potentially harmful ones (most errors will be, most warnings will not be), and make sure the others are justifiable. In this case, it would add code bulk to your site with no benefit to a user, and as such, fixing the warning would seem to be a mistake.

2
  • I agree with your clarifications, but I work with SEO and the client does not understand that warnings are different from errors. I found a solution posted today in this topic stackoverflow.com/questions/48038551/…. I think the tag will be removed in future Joomla looks like you said. Thanks for the clarification anyway!
    – Ricardo
    Jan 10, 2018 at 2:17
  • Ah! Wasn't aware of setHtml5. Good to know.
    – RichardB
    Jan 10, 2018 at 14:36
1

The solution was found by user FabrizioG adding the following line in the index.php of the template:

// Set HTML5 Document Output
$doc = JFactory::getDocument();
$doc->setHtml5(true); 

Some warnings remain because I use JCHOPtimize, it was easily solved by removing the "type" attribute in file linkbuilder.php

0

With the newest Joomla 3.9.x - its hard coded in the script and: $doc->setHtml5(true) - doesn't seem to work.

My solution was to edit the file in /libraries/cms/html/email.php

Change:

$inlineScript = "<script type='text/javascript'>" . $script . "</script>";

to

$inlineScript = "<script>" . $script . "</script>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.