Issue Bug Closed

#38146External file concatenation takes place on every page request

Björn Schmitt 06/18/12, 11:23 updated 06/15/15, 14:02

Description

If concatenateJs/Css=1 is enabled external files will get downloaded on every page request. This is unnecessary and reduces speed.

    // t3lib/class.t3lib_compressor.php
    protected function retrieveExternalFile($url) {
        $filename = $this->targetDirectory . 'external-' . md5($url);
        $externalContent = t3lib_div::getUrl($url);
        t3lib_div::writeFile(PATH_site . $filename, $externalContent);
        return $filename;
    }

The main problem is that concatenation will not work as expected because the modified timestamp of all files is used to generate an unique md5 hash as identifier. On every page request these external files will get downloaded and hence they will get a new creation date / modified date. That’s the reason why the concatenation hash differs and a new merged file is created for every request.

    // t3lib/class.t3lib_compressor.php -> createMergedFile
    ...
    // we add up the filenames, filemtimes and filsizes to later build a checksum over
    // it and include it in the temporary file name
    $unique = '';
    foreach ($filesToInclude as $key => $filename) {
        if (t3lib_div::isValidUrl($filename)) {
            $filesToInclude[$key] = $this->retrieveExternalFile($filename);
            $filename = $filesToInclude[$key];
        }
        $filepath = t3lib_div::resolveBackPath($this->rootPath . $filename);
        $unique .= $filename . filemtime($filepath) . filesize($filepath);
    }

In best case these external files will only get downloaded after a clear cache command, that would fix the creation date problem and a will allow browser caching.

This issue is a follow up to http://forge.typo3.org/issues/29695 and the appropriate review https://review.typo3.org/#/c/4924/1/t3lib/class.t3lib_compressor.php

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.