Issue Bug Closed

#90208includeJS + defer does not work if the ResourceCompressor has done its job

C. Gogolin 01/26/20, 13:02 updated 04/01/20, 21:14

Description

I use Typo3 9.5.13.

According to the documentation the attribute defer is supported:

Typo3:
[[https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.0/Feature-80542-TypoScriptJavaScriptDeferAttribute.html]]

defer:
[[https://www.w3schools.com/tags/att_script_defer.asp]]

Here is an example typo scripting:

page.includeJS.a2hs = /fileadmin/a2hs/a2hs.js
page.includeJS.a2hs.defer = 1

But unfortunately the defer attribute is not included in the HTML source code.

After my analysis the defer flag arrives in PageRenderer and is placed in the array $this->jsFiles. But then comes the ResourceCompressor:

In the method
@ResourceCompressor#concatenateJsFiles(array $jsFiles)@ will “forget” the defer flag.

Unfortunately this method is too complicated for me and I don’t know which attributes still disappear like this. Otherwise I would have submitted a correction suggestion here.

Thanks for your help.

My current workaround is:
@
page.headerData.30 = TEXT
page.headerData.30.value = <script src="/fileadmin/a2hs/a2hs.js" defer></script>@

Translated with www.DeepL.com/Translator (free version)

Reviews 2