According to current specification for HTML 5 compliant browsers, the type attribute of script tags isn't required if the type is JavaScript. Modern browsers automatically identify omitted script types as JavaScript. No matter what value is sent as type attribute, type will be added, even sending an empty string.
JFactory::getDocument()->addScript('script.js', array(), array('type' => ''));
Becomes:
<script src="script.js" type=""></script>
To avoid setting off any deprecated behavior (but also not break backwards compatibility), why not have it set so that if a user provides an empty string for type, the type attribute isn't set.
JFactory::getDocument()->addScript('script.js', array(), array('type' => ''));
Becomes:
<script src="script.js"></script>
Labels |
Added:
?
|
Honestly, I feel like somewhere along the line, I just failed to read/understand the documentation for templates and missed that line entirely. Thank you for pointing it out.
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-09-07 15:25:04 |
Closed_By | ⇒ | franz-wohlkoenig |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/22039
closed as Issue looking solved. If i'm wrong please pardon and reopen.
You should still pass the type forward when registering scripts.
The
HtmlDocument
class has a parameter to toggle whether the document is built as HTML5 or HTML4/XHTML (it defaults to HTML4/XHTML in 3.x and in 4.0 defaults to HTML5), and the script rendering process already omits the type attribute in this case.So best practice should be to always pass the type. If you're building a template and want it to output as a HTML5 document, call
$this->setHtml5(true);
in your template's index.php file and core will take care of altering the output as appropriate.