Skip to content

Commit

Permalink
[BUGFIX] Do not set type=text/javascript in ResourceCompressor
Browse files Browse the repository at this point in the history
The ResourceCompressor should not hard-code the JS file
type when concatenating JS files.

Resolves: #91310
Releases: master, 10.4
Change-Id: I70f5428cb184aeee36467d0de5327acd167dca4e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64414
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
rafu1987 authored and maddy2101 committed Aug 15, 2020
1 parent ef82fa9 commit 1cbf3d5
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion typo3/sysext/core/Classes/Resource/ResourceCompressor.php
Expand Up @@ -19,6 +19,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Compressor
Expand Down Expand Up @@ -182,11 +183,12 @@ public function concatenateJsFiles(array $jsFiles)
unset($jsFiles[$key]);
}
if (!empty($filesToInclude)) {
$defaultTypeAttributeForJavaScript = $this->getJavaScriptFileType();
foreach ($filesToInclude as $section => $files) {
$targetFile = $this->createMergedJsFile($files);
$concatenatedOptions = [
'file' => $targetFile,
'type' => 'text/javascript',
'type' => $defaultTypeAttributeForJavaScript,
'section' => $section,
'compress' => true,
'excludeFromConcatenation' => true,
Expand Down Expand Up @@ -698,4 +700,25 @@ protected function compressCssString($contents)
$contents .= LF;
return $contents;
}

/**
* Determines the the JavaScript mime type
*
* The <script> tag only needs the type if the page is not rendered as HTML5.
* In TYPO3 Backend or when TSFE is not available we always use HTML5.
* For TYPO3 Frontend the configured config.doctype is evaluated.
*
* @return string
*/
protected function getJavaScriptFileType(): string
{
if (TYPO3_MODE === 'BE' || !isset($GLOBALS['TSFE']) || !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)) {
// Backend (or at least no TSFE), always HTML5
return '';
}
if (($GLOBALS['TSFE']->config['config']['doctype'] ?? 'html5') === 'html5') {
return '';
}
return 'text/javascript';
}
}

0 comments on commit 1cbf3d5

Please sign in to comment.