ResourceCompressor

Compressor This merges and compresses CSS and JavaScript files of the TYPO3 Backend.

Table of Contents

Properties

$createGzipped  : bool
gzipped versions are only created if $TYPO3_CONF_VARS['BE' or 'FE']['compressionLevel'] is set
$gzipCompressionLevel  : int
$htaccessTemplate  : string
$rootPath  : string
$targetDirectory  : string

Methods

__construct()  : mixed
Constructor
compressCssFile()  : string
Compresses a CSS file
compressCssFiles()  : array<string|int, mixed>
Compress multiple css files
compressJavaScriptSource()  : string
compressJsFile()  : string
Compresses a javascript file
compressJsFiles()  : array<string|int, mixed>
Compress multiple javascript files
concatenateCssFiles()  : array<string|int, mixed>
Concatenates the Stylesheet files
concatenateJsFiles()  : array<string|int, mixed>
Concatenates the JavaScript files
setRootPath()  : mixed
Sets absolute path to working directory
checkBaseDirectory()  : bool
Decides whether a file comes from one of the baseDirectories
compressCssString()  : string
Compress a CSS string by removing comments and whitespace characters
createMergedCssFile()  : mixed
Creates a merged CSS file
createMergedFile()  : mixed
Creates a merged file with given file type
createMergedJsFile()  : mixed
Creates a merged JS file
cssFixRelativeUrlPaths()  : string
cssFixStatements()  : string
Moves @charset, @import and @namespace statements to the top of the content, because they must occur before all other CSS rules
getFilenameFromMainDir()  : string
Finds the relative path to a file, relative to the root path.
getJavaScriptFileType()  : string
Determines the the JavaScript mime type
getPathFixer()  : RelativeCssPathFixer
retrieveExternalFile()  : string
Retrieves an external file and stores it locally.
returnFileReference()  : string
Decides whether a client can deal with gzipped content or not and returns the according file name, based on HTTP_ACCEPT_ENCODING
writeFileAndCompressed()  : mixed
Writes $contents into file $filename together with a gzipped version into $filename.gz

Properties

$createGzipped

gzipped versions are only created if $TYPO3_CONF_VARS['BE' or 'FE']['compressionLevel'] is set

protected bool $createGzipped = false

$gzipCompressionLevel

protected int $gzipCompressionLevel = -1

$htaccessTemplate

protected string $htaccessTemplate = '<FilesMatch "\.(js|css)(\.gzip)?$"> <IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 7 days" </IfModule> FileETag MTime Size </FilesMatch>'

$targetDirectory

protected string $targetDirectory = 'typo3temp/assets/compressed/'

Methods

__construct()

Constructor

public __construct() : mixed

compressCssFile()

Compresses a CSS file

public compressCssFile(string $filename) : string

Options: baseDirectories If set, only include files below one of the base directories

removes comments and whitespaces Adopted from https://github.com/drupal/drupal/blob/8.0.x/core/lib/Drupal/Core/Asset/CssOptimizer.php

Parameters
$filename : string

Source filename, relative to requested page

Return values
string

Compressed filename, relative to requested page

compressCssFiles()

Compress multiple css files

public compressCssFiles(array<string|int, mixed> $cssFiles) : array<string|int, mixed>
Parameters
$cssFiles : array<string|int, mixed>

The files to compress (array key = filename), relative to requested page

Return values
array<string|int, mixed>

The CSS files after compression (array key = new filename), relative to requested page

compressJavaScriptSource()

public compressJavaScriptSource(string $javaScriptSourceCode) : string
Parameters
$javaScriptSourceCode : string
Return values
string

compressJsFile()

Compresses a javascript file

public compressJsFile(string $filename) : string
Parameters
$filename : string

Source filename, relative to requested page

Return values
string

Filename of the compressed file, relative to requested page

compressJsFiles()

Compress multiple javascript files

public compressJsFiles(array<string|int, mixed> $jsFiles) : array<string|int, mixed>
Parameters
$jsFiles : array<string|int, mixed>

The files to compress (array key = filename), relative to requested page

Return values
array<string|int, mixed>

The js files after compression (array key = new filename), relative to requested page

concatenateCssFiles()

Concatenates the Stylesheet files

public concatenateCssFiles(array<string|int, mixed> $cssFiles) : array<string|int, mixed>
Parameters
$cssFiles : array<string|int, mixed>

CSS files to process

Return values
array<string|int, mixed>

CSS files

concatenateJsFiles()

Concatenates the JavaScript files

public concatenateJsFiles(array<string|int, mixed> $jsFiles) : array<string|int, mixed>
Parameters
$jsFiles : array<string|int, mixed>

JavaScript files to process

Return values
array<string|int, mixed>

JS files

setRootPath()

Sets absolute path to working directory

public setRootPath(string $rootPath) : mixed
Parameters
$rootPath : string

Absolute path

checkBaseDirectory()

Decides whether a file comes from one of the baseDirectories

protected checkBaseDirectory(string $filename, array<string|int, mixed> $baseDirectories) : bool
Parameters
$filename : string

Filename

$baseDirectories : array<string|int, mixed>

Base directories

Return values
bool

File belongs to a base directory or not

compressCssString()

Compress a CSS string by removing comments and whitespace characters

protected compressCssString(string $contents) : string
Parameters
$contents : string
Return values
string

createMergedCssFile()

Creates a merged CSS file

protected createMergedCssFile(array<string|int, mixed> $filesToInclude) : mixed
Parameters
$filesToInclude : array<string|int, mixed>

Files which should be merged, paths relative to root path

Return values
mixed

Filename of the merged file

createMergedFile()

Creates a merged file with given file type

protected createMergedFile(array<string|int, mixed> $filesToInclude[, string $type = 'css' ]) : mixed
Parameters
$filesToInclude : array<string|int, mixed>

Files which should be merged, paths relative to root path

$type : string = 'css'

File type

Tags
throws
InvalidArgumentException
Return values
mixed

Filename of the merged file

createMergedJsFile()

Creates a merged JS file

protected createMergedJsFile(array<string|int, mixed> $filesToInclude) : mixed
Parameters
$filesToInclude : array<string|int, mixed>

Files which should be merged, paths relative to root path

Return values
mixed

Filename of the merged file

cssFixRelativeUrlPaths()

protected cssFixRelativeUrlPaths(string $contents, string $filename) : string
Parameters
$contents : string
$filename : string
Return values
string

cssFixStatements()

Moves @charset, @import and @namespace statements to the top of the content, because they must occur before all other CSS rules

protected cssFixStatements(string $contents) : string
Parameters
$contents : string

Data to process

Return values
string

Processed data

getFilenameFromMainDir()

Finds the relative path to a file, relative to the root path.

protected getFilenameFromMainDir(string $filename) : string
Parameters
$filename : string

the name of the file

Return values
string

the path to the file relative to the root path ($this->rootPath)

getJavaScriptFileType()

Determines the the JavaScript mime type

protected getJavaScriptFileType() : string

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 values
string

retrieveExternalFile()

Retrieves an external file and stores it locally.

protected retrieveExternalFile(string $url) : string
Parameters
$url : string
Return values
string

Temporary local filename for the externally-retrieved file

returnFileReference()

Decides whether a client can deal with gzipped content or not and returns the according file name, based on HTTP_ACCEPT_ENCODING

protected returnFileReference(string $filename) : string
Parameters
$filename : string

File name

Return values
string

$filename suffixed with '.gzip' or not - dependent on HTTP_ACCEPT_ENCODING

writeFileAndCompressed()

Writes $contents into file $filename together with a gzipped version into $filename.gz

protected writeFileAndCompressed(string $filename, string $contents) : mixed
Parameters
$filename : string

Target filename

$contents : string

File contents


        
On this page

Search results