Feature: #91715 - Add multiple has($identifier) methods to TYPO3CMSCorePageAssetCollector

See forge#91715


The new feature can check if the assets such as javascript, inline style sheets, style sheets, and media already exist before generating it again.

To accomplish this, new methods has been added to \TYPO3\CMS\Core\Page\AssetCollector:

  • hasJavaScript(string $identifier): bool

  • hasInlineJavaScript(string $identifier): bool

  • hasStyleSheet(string $identifier): bool

  • hasInlineStyleSheet(string $identifier): bool

  • hasMedia(string $identifier): bool

//use TYPO3\CMS\Core\Page\AssetCollector;
//use TYPO3\CMS\Core\Utility\GeneralUtility;

$assetsCollector = GeneralUtility::makeInstance(AssetCollector::class);
if ($assetsCollector->hasJavaScript($identifier)) {
  // result: true - javascript with identifier $identifier exists
} else {
  // result: false - javascript with identifier $identifier do not exists

// $result<X> is true if $identifier exists, otherwise false.
$result1 = $assetsCollector->hasJavaScript($identifier);
$result2 = $assetsCollector->hasInlineJavaScript($identifier);
$result3 = $assetsCollector->hasStyleSheet($identifier);
$result4 = $assetsCollector->hasInlineStyleSheet($identifier);
$result5 = $assetsCollector->hasMedia($identifier);


Users get the option to check if the asset exists before generating it again, hence avoiding redundancy.