PHPackages                             lochmueller/sourceopt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lochmueller/sourceopt

ActiveTypo3-cms-extension[Utility &amp; Helpers](/categories/utility)

lochmueller/sourceopt
=====================

Optimization of the final page: reformatting the (x)HTML output &amp; removal of new-lines, comments and generator-info including search and replace strings using your regular expressions. In addition combines all SVG selected within content-elements into one &lt;symbol&gt; file and replaces &lt;img&gt; by &lt;use&gt;.

5.2.9(4mo ago)24557.0k—3.2%20[2 PRs](https://github.com/lochmueller/sourceopt/pulls)2GPL-2.0-or-laterPHPPHP ^8.1CI failing

Since Jun 15Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/lochmueller/sourceopt)[ Packagist](https://packagist.org/packages/lochmueller/sourceopt)[ Docs](https://github.com/lochmueller/sourceopt)[ Fund](https://paypal.me/lochmueller)[ GitHub Sponsors](https://github.com/lochmueller)[ RSS](/packages/lochmueller-sourceopt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (28)Used By (2)

EXT:sourceopt
=============

[](#extsourceopt)

[![Build Status](https://github.com/lochmueller/sourceopt/workflows/Tests/badge.svg)](https://github.com/lochmueller/sourceopt/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0892508b670297f5be1a0186e7ae052ea49398d8fce5c60d67d98e6d284113cd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6f63686d75656c6c65722f736f757263656f70742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lochmueller/sourceopt/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/90c754a88e9fcc660380e413a64228ad40fbaeb8ade8bcc86f48f770b84d3ffe/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6f63686d75656c6c65722f736f757263656f70742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lochmueller/sourceopt/?branch=master)

- [SourceOpt](#sourceopt) : reformatting the (x)HTML output &amp; removal of new-lines, comments and generator-info
- [RegExRep](#regex-replace) : search and replace strings using your regular expressions ; [embrace regex](https://www.regular-expressions.info) and [migrate now](#howto-migrate)
- [SVGstore](#svgstore) : combines all SVG selected within elements into one &lt;symbol&gt; file and replaces &lt;img&gt; by &lt;use&gt;

Version
-------

[](#version)

#### &gt;= 5.2.5

[](#-525)

 [sourceopt/composer.json](https://github.com/lochmueller/sourceopt/blob/173f7bd2a44b546844961ced1f0831371badd620/composer.json#L8-L9)

 Lines 8 to 9 in [173f7bd](/lochmueller/sourceopt/commit/173f7bd2a44b546844961ced1f0831371badd620)

     "php": "^8.1",      "typo3/cms-core": "^12.4||^13.4"

#### &lt;= 5.2.0 (legacy)

[](#-520-legacy)

 [sourceopt/composer.json](https://github.com/lochmueller/sourceopt/blob/6663a8a8512ba280bc7e8b8d38610146495a94ce/composer.json#L8-L9)

 Lines 8 to 9 in [6663a8a](/lochmueller/sourceopt/commit/6663a8a8512ba280bc7e8b8d38610146495a94ce)

     "php": "^7.4||^8.0",      "typo3/cms-core": "^9.5||^10.4||^11.5||^12.4"

Installation
------------

[](#installation)

```
composer require lochmueller/sourceopt
```

- via *TypoScript*

    `[constants]`

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

    ```

    `[setup]`

    ```
    @import 'EXT:sourceopt/Configuration/TypoScript/setup'

    ```
- via input device

    - add `[EXT:sourceopt/Configuration/TypoScript]` into **`Include static`** at `Includes` in `Template`

Configuration
-------------

[](#configuration)

Include the extension and go to the `Constant Editor` of a template where you find all options under `PLUGIN`

Performance
-----------

[](#performance)

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

Reference
---------

[](#reference)

Note: The following features are executed in reverse order

### SourceOpt

[](#sourceopt)

*TypoScript* `[constants]` || prepend `config.` at `[setup]`

PropertyTypeDescriptionDefaultsourceopt.enabledbooleanIs the optimization enabled for this template1sourceopt.removeGeneratorbooleanRemove &lt;meta name="generator" content="TYPO3 CMS"&gt;1sourceopt.removeCommentsbooleanRemove HTML-Comments1sourceopt.removeComments.keeparraySpare 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.10stringSpare TYPO3SEARCH-Comments from removal/^TYPO3SEARCH\_/usisourceopt.headerCommentstringYour additional (appended) header comment`[empty]`sourceopt.formatHtmlintegerFormats the code beautiful and easy readable. New lines and tabs are used in the usual way of illustrating the structure of an XML code. **Options** [sourceopt/Classes/Service/CleanHtmlService.php](https://github.com/lochmueller/sourceopt/blob/2346673ee51d2b64308e1ddb1433cea2f37eafcb/Classes/Service/CleanHtmlService.php#L156-L161)

 Lines 156 to 161 in [2346673](/lochmueller/sourceopt/commit/2346673ee51d2b64308e1ddb1433cea2f37eafcb)

      \* 0 =&gt; off       \* 1 =&gt; no line break at all (code in one line)       \* 2 =&gt; minimalistic line breaks (structure defining box-elements)       \* 3 =&gt; aesthetic line breaks (important box-elements)       \* 4 =&gt; logic line breaks (all box-elements)       \* 5 =&gt; max line breaks (all elements).

4sourceopt.formatHtml.tabSizeintegerDefines 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.debugCommentbooleanIncludes 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

[](#regex-replace)

*TypoScript* `[setup]` incl. [`stdWrap`](https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/Functions/Stdwrap.html)

```
config.replacer {
  search {
    1 = /(?
