2017 © Pedro Peláez
 

typo3-cms-extension sourceopt

Optimization of the final page: reformatting the (x)html output, removal of new lines, and quotes.

image

lochmueller/sourceopt

Optimization of the final page: reformatting the (x)html output, removal of new lines, and quotes.

  • Wednesday, April 11, 2018
  • by lochmueller
  • Repository
  • 6 Watchers
  • 11 Stars
  • 21,998 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 5 Forks
  • 7 Open issues
  • 3 Versions
  • 21 % Grown

The README.md

EXT:sourceopt

Build Status Scrutinizer Code Quality Code Coverage, (*1)

  • SourceOpt : reformatting the (x)HTML output & removal of new-lines, comments and generator-info
  • RegExRep : search and replace strings using your regular expressions ; embrace regex and migrate now
  • SVGstore : combines all SVG selected within elements into one <symbol> file and replaces <img> by <use>

Version

>= 5.2.5

https://github.com/lochmueller/sourceopt/blob/173f7bd2a44b546844961ced1f0831371badd620/composer.json#L8-L9, (*2)

<= 5.2.0 (legacy)

https://github.com/lochmueller/sourceopt/blob/6663a8a8512ba280bc7e8b8d38610146495a94ce/composer.json#L8-L9, (*3)

Installation

composer require lochmueller/sourceopt
  • via TypoScript, (*4)

    [constants], (*5)

    @import 'EXT:sourceopt/Configuration/TypoScript/constants'
    

    [setup], (*6)

    @import 'EXT:sourceopt/Configuration/TypoScript/setup'
    
  • via input device
    • add [EXT:sourceopt/Configuration/TypoScript] into Include static at Includes in Template

Configuration

Include the extension and go to the Constant Editor of a template where you find all options under PLUGIN, (*7)

Performance

The PHP process need server performance, because there are several search/replace operations in the logic, (*8)

Reference

Note: The following features are executed in reverse order, (*9)

SourceOpt

TypoScript [constants] || prepend config. at [setup] , (*10)

Property Type Description Default
sourceopt.enabled boolean Is the optimization enabled for this template 1
sourceopt.removeGenerator boolean Remove <meta name="generator" content="TYPO3 CMS"> 1
sourceopt.removeComments boolean Remove HTML-Comments 1
sourceopt.removeComments.keep array Spare these listed comments: Regular expressions that match comments that should not be removed. Very useful e.g. to keep the TYPO3SEARCH-Comments so indexed_search can work properly .10
sourceopt.removeComments.keep.10 string Spare TYPO3SEARCH-Comments from removal /^TYPO3SEARCH_/usi
sourceopt.headerComment string Your additional (appended) header comment [empty]
sourceopt.formatHtml integer Formats the code beautiful and easy readable. New lines and tabs are used in the usual way of illustrating the structure of an XML code.
Optionshttps://github.com/lochmueller/sourceopt/blob/2346673ee51d2b64308e1ddb1433cea2f37eafcb/Classes/Service/CleanHtmlService.php#L156-L161
4
sourceopt.formatHtml.tabSize integer Defines the size of the tabs used for formating. If blank one tab is used. If a number is specified the specified number of blank spaces is used instead. This will only work together with formatHtml [empty]
sourceopt.formatHtml.debugComment boolean Includes a comment at the end of the html source code that points the numbers of open html tags. This will only work together with formatHtml [empty]

RegEx Replace

TypoScript [setup] incl. stdWrap, (*11)

config.replacer {
  search {
    1 = /(?<="|')\/?(fileadmin|typo3temp|uploads)/

    give-me-cherries = /fruit/

    wrapBoldly < tmp.find
    wrapBoldly.wrap = /|/
  }
  replace {
    1 = //cdn.tld/$1

    give-me-cherries = cherry

    wrapBoldly < tmp.repl
    wrapBoldly.wrap = <b>|</b>
  }
}

Note: both arrays will be ksort'ed in "natural order", (*12)

, (*13)

HowTo migrate

, (*14)

from jweiland/replacer : 1.4 - 2.x

, (*15)

  • regex replace config\.tx_(?:\w*replace\w*) to config.replacer
  • remove config.tx_replacer.enable_regex = 1

, (*16)

from maxserv/replacecontent 2013 - 2017

, (*17)

  • regex replace config\.tx_(?:\w*replace\w*) to config.replacer

, (*18)

from typo3-ter/ja_replacer 2009 - 2013 || phorax/ja-replacer 2016

, (*19)

composer install jweiland/replacer

& replace config.tx_ja_replacer to config.tx_replacer, (*20)

, (*21)

from typo3-ter/n84_contentreplacer 2016

, (*22)

  • regex replace config\.tx_(?:\w*replace\w*) to config.replacer

, (*23)

from typo3-ter/fereplace 2011

, (*24)

composer install jweiland/replacer

& replace plugin.fereplace.pairs to config.tx_replacer .. ah .. and one regex - search (\n\s*)(\d+)(?:{\s+|\.)old\s*=\s*([^\n]+).+?new\s*=\s*([^\n]+) - replace $1search.$2 = $3\n$1replace.$2 = $4, (*25)

, (*26)

from typo3-ter/regex 2009

, (*27)

  • regex replace config\.regex to config.replacer
  • regex replace (?:\s)(\w+)\s*=\s* to search.$1 =
  • regex replace (\w+)\.replacement\s*=\s* to replace.$1 =

, (*28)

from any other tool or just for regex

, (*29)

  • regex replace (?:config|plugin)\.tx_any_other_tool to config.replacer
  • inside block search
    • regex replace \/ to \\/ (carefully)
    • regex replace \s*=\s*(.+) to = /$1/
  • inside block replace
    • regex replace \s*=\s*(.+) to = $1
    • consider a PR for conversion specifics

, (*30)

SVGstore

TypoScript [constants] || prepend config. at [setup] , (*31)

Property Type Description Default
svgstore.enabled boolean Is the SVG extract & merge enabled for this template 1
svgstore.fileSize integer Maximum file size of a SVG to include (in [byte]) 50000

ToDo:
  • Try external packages like https://github.com/ArjanSchouten/HtmlMinifier

The Versions

11/04 2018

dev-master

9999999-dev https://github.com/lochmueller/sourceopt

Optimization of the final page: reformatting the (x)html output, removal of new lines, and quotes.

  Sources   Download

The Requires

 

The Development Requires

15/06 2017

1.0.0

1.0.0.0 https://github.com/lochmueller/sourceopt

Optimization of the final page: reformatting the (x)html output, removal of new lines, and quotes.

  Sources   Download

The Requires

 

The Development Requires

15/06 2016

0.9.3

0.9.3.0 https://github.com/lochmueller/sourceopt

Optimization of the final page: reformatting the (x)html output, removal of new lines, and quotes.

  Sources   Download

The Requires

 

The Development Requires