You are here

public function AmpCssCollectionRenderer::minify in Accelerated Mobile Pages (AMP) 8.3

Minify and optimize css.

Some code copied from color_scheme_form_submit() which rewrites css to replace colors in css files.

Parameters

string $style: The css to minify.

Return value

string The minified css.

2 calls to AmpCssCollectionRenderer::minify()
AmpCssCollectionRenderer::doRewrite in src/Asset/AmpCssCollectionRenderer.php
Rewrite relative urls in css.
AmpCssCollectionRenderer::render in src/Asset/AmpCssCollectionRenderer.php
Renders an asset collection.

File

src/Asset/AmpCssCollectionRenderer.php, line 250

Class

AmpCssCollectionRenderer
Renders CSS assets.

Namespace

Drupal\amp\Asset

Code

public function minify($style) {

  // Remove comments.
  $style = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $style);

  // Remove space after colons.
  $style = str_replace(': ', ':', $style);

  // Remove whitespace.
  $style = str_replace([
    "\r\n",
    "\r",
    "\n",
    "\t",
    '  ',
    '    ',
    '    ',
  ], '', $style);
  return $style;
}