Skip to content

Commit c30e8aa

Browse files
committed
Aggressively remove spaces between tags
Signed-off-by: Cees-Jan Kiewiet <ceesjank@gmail.com>
1 parent 1a4d9b8 commit c30e8aa

File tree

10 files changed

+12
-11
lines changed

10 files changed

+12
-11
lines changed

src/Compressor/HtmlCompressor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class HtmlCompressor implements CompressorInterface
1515
public function __construct(Patterns $patterns)
1616
{
1717
$this->htmlMin = new HtmlMin();
18+
$this->htmlMin->doRemoveSpacesBetweenTags(true);
1819
$this->htmlMin->attachObserverToTheDomLoop(new HtmlMinObserver($patterns));
1920
}
2021

tests/Compressor/HtmlCompressorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function providerMultipleSpaces(): iterable
5858
];
5959
yield [
6060
"<html>\n <head> </head>\n <body>\n <p id=\"text\" class=\"foo\">\n foo\n </p> <br /> <ul > <li> <p class=\"foo\">lall</p> </li></ul>\n </body>\n </html>",
61-
'<html><head> <body><p class=foo id=text> foo </p> <br> <ul><li><p class=foo>lall </ul>',
61+
'<html><head><body><p class=foo id=text> foo </p><br><ul><li><p class=foo>lall </ul>',
6262
];
6363
}
6464

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><link href=/css/style.css?1453088025 media=all rel=stylesheet> <body><header><nav></nav> </header>
1+
<!DOCTYPE html><html><head><link href=/css/style.css?1453088025 media=all rel=stylesheet><body><header><nav></nav></header>

tests/EdgeCases/asciinema/out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313

1414
$socket-&gt;listen(1337);
1515
$loop-&gt;run();
16-
</code></pre> <script async id=asciicast-18487 src=https://asciinema.org/a/18487.js></script>
16+
</code></pre><script async id=asciicast-18487 src=https://asciinema.org/a/18487.js></script>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>pre code{background-color:inherit}</style> <body class=blog><header><nav></nav> </header> <script>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script>
1+
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>pre code{background-color:inherit}</style><body class=blog><header><nav></nav></header><script>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>pre code{background-color:inherit}</style><script type=application/ld+json>{"@context":"https:\/\/schema.org\/","@graph":[{"@context":"https:\/\/schema.org\/","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"name":"Home","@id":"http:\/\/domain.com"}},{"@type":"ListItem","position":2,"item":{"name":"Category title","@id":"http:\/\/domain.com\/product-category\/category-name\/"}},{"@type":"ListItem","position":3,"item":{"name":"Sub Category title","@id":"http:\/\/domain.com\/product-category\/category-name\/sub-category-name\/"}}]},{"@context":"https:\/\/schema.org\/","@graph":[{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-potiron\/","name":"Mijot\u00e9e de potiron","url":"http:\/\/domain.com\/product\/mijote-de-potiron\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-haricot-vert-2\/","name":"Mijot\u00e9e de haricot vert","url":"http:\/\/domain.com\/product\/mijote-de-haricot-vert-2\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-carotte-2\/","name":"Mijot\u00e9e de carotte","url":"http:\/\/domain.com\/product\/mijote-de-carotte-2\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-petit-pois\/","name":"Mijot\u00e9e de petit pois","url":"http:\/\/domain.com\/product\/mijote-de-petit-pois\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-patate-douce\/","name":"Mijot\u00e9e de patate douce","url":"http:\/\/domain.com\/product\/mijote-de-patate-douce\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-brocoli-2\/","name":"Mijot\u00e9e de brocoli","url":"http:\/\/domain.com\/product\/mijote-de-brocoli-2\/"}]}]}</script> <body class=blog><header><nav></nav> </header> <script>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script>
1+
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>pre code{background-color:inherit}</style><script type=application/ld+json>{"@context":"https:\/\/schema.org\/","@graph":[{"@context":"https:\/\/schema.org\/","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"name":"Home","@id":"http:\/\/domain.com"}},{"@type":"ListItem","position":2,"item":{"name":"Category title","@id":"http:\/\/domain.com\/product-category\/category-name\/"}},{"@type":"ListItem","position":3,"item":{"name":"Sub Category title","@id":"http:\/\/domain.com\/product-category\/category-name\/sub-category-name\/"}}]},{"@context":"https:\/\/schema.org\/","@graph":[{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-potiron\/","name":"Mijot\u00e9e de potiron","url":"http:\/\/domain.com\/product\/mijote-de-potiron\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-haricot-vert-2\/","name":"Mijot\u00e9e de haricot vert","url":"http:\/\/domain.com\/product\/mijote-de-haricot-vert-2\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-carotte-2\/","name":"Mijot\u00e9e de carotte","url":"http:\/\/domain.com\/product\/mijote-de-carotte-2\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-petit-pois\/","name":"Mijot\u00e9e de petit pois","url":"http:\/\/domain.com\/product\/mijote-de-petit-pois\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-patate-douce\/","name":"Mijot\u00e9e de patate douce","url":"http:\/\/domain.com\/product\/mijote-de-patate-douce\/"},{"@type":"Product","@id":"http:\/\/domain.com\/product\/mijote-de-brocoli-2\/","name":"Mijot\u00e9e de brocoli","url":"http:\/\/domain.com\/product\/mijote-de-brocoli-2\/"}]}]}</script><body class=blog><header><nav></nav></header><script>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script>

tests/EdgeCases/ld-json/out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>pre code{background-color:inherit}</style><script type=application/ld+json>{"@context":"http://schema.org/","@type":"Product","name":"Yoast SEO for WordPress","image":"https://cdn-images.yoast.com/uploads/2010/10/Yoast_SEO_WP_plugin_FB.png","description":"Yoast SEO is the most complete WordPress SEO plugin. It handles the technical optimization of your site & assists with optimizing your content.","brand":{"@type":"Thing","name":"Yoast"},"offers":{"@type":"Offer","priceCurrency":"USD","price":"69.00"}}</script> <body class=blog><header><nav></nav> </header> <script>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script>
1+
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>pre code{background-color:inherit}</style><script type=application/ld+json>{"@context":"http://schema.org/","@type":"Product","name":"Yoast SEO for WordPress","image":"https://cdn-images.yoast.com/uploads/2010/10/Yoast_SEO_WP_plugin_FB.png","description":"Yoast SEO is the most complete WordPress SEO plugin. It handles the technical optimization of your site & assists with optimizing your content.","brand":{"@type":"Thing","name":"Yoast"},"offers":{"@type":"Offer","priceCurrency":"USD","price":"69.00"}}</script><body class=blog><header><nav></nav></header><script>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script>

tests/Factory/fastest/out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style>/** quick fix because bootstrap <pre> has a background-color. */
2-
pre code { background-color: inherit; }</style> <body class=blog><header><nav></nav> </header> <script>window.jQuery || document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>');
2+
pre code { background-color: inherit; }</style><body class=blog><header><nav></nav></header><script>window.jQuery || document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>');
33
alert('hoi');</script>

tests/Factory/normal/out.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style rng=/dev/null rsync=off>pre code{background-color:inherit}</style> <body class=blog style=background-color:red><header><nav></nav> </header> <script>alert('hoi')</script> <hr> <script rng=/dev/null rsync=off>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script> <hr> <script rng=/dev/null rsync=off type=text/javascript>alert('hoi')</script> <hr> <script rng=/dev/null type=language/dutch>Goede morgen,
1+
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style rng=/dev/null rsync=off>pre code{background-color:inherit}</style><body class=blog style=background-color:red><header><nav></nav></header><script>alert('hoi')</script><hr><script rng=/dev/null rsync=off>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script><hr><script rng=/dev/null rsync=off type=text/javascript>alert('hoi')</script><hr><script rng=/dev/null type=language/dutch>Goede morgen,
22
Goede middag,
3-
Goede avond</script> <hr> <script type=application/ld+json>{"@context":"http://schema.org/","@type":"Product","name":"Yoast SEO for WordPress","image":"https://cdn-images.yoast.com/uploads/2010/10/Yoast_SEO_WP_plugin_FB.png","description":"Yoast SEO is the most complete WordPress SEO plugin. It handles the technical optimization of your site & assists with optimizing your content.","brand":{"@type":"Thing","name":"Yoast"},"offers":{"@type":"Offer","priceCurrency":"USD","price":"69.00"}}</script>
3+
Goede avond</script><hr><script type=application/ld+json>{"@context":"http://schema.org/","@type":"Product","name":"Yoast SEO for WordPress","image":"https://cdn-images.yoast.com/uploads/2010/10/Yoast_SEO_WP_plugin_FB.png","description":"Yoast SEO is the most complete WordPress SEO plugin. It handles the technical optimization of your site & assists with optimizing your content.","brand":{"@type":"Thing","name":"Yoast"},"offers":{"@type":"Offer","priceCurrency":"USD","price":"69.00"}}</script>

tests/Factory/smallest/out.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style rng=/dev/null rsync=off>pre code{background-color:inherit}</style> <body class=blog style=background-color:red><header><nav></nav> </header> <script>alert('hoi')</script> <hr> <script rng=/dev/null rsync=off>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script> <hr> <script rng=/dev/null rsync=off type=text/javascript>alert('hoi')</script> <hr> <script rng=/dev/null type=language/dutch>Goede morgen,
1+
<!DOCTYPE html><html><head><meta content="noindex, follow" name=robots><style rng=/dev/null rsync=off>pre code{background-color:inherit}</style><body class=blog style=background-color:red><header><nav></nav></header><script>alert('hoi')</script><hr><script rng=/dev/null rsync=off>window.jQuery||document.write('<script src="http://blog.wyrihaximus.net/components/jquery/jquery.min.js"><\/script>')</script><hr><script rng=/dev/null rsync=off type=text/javascript>alert('hoi')</script><hr><script rng=/dev/null type=language/dutch>Goede morgen,
22
Goede middag,
3-
Goede avond</script> <hr> <script type=application/ld+json>{"@context":"http://schema.org/","@type":"Product","name":"Yoast SEO for WordPress","image":"https://cdn-images.yoast.com/uploads/2010/10/Yoast_SEO_WP_plugin_FB.png","description":"Yoast SEO is the most complete WordPress SEO plugin. It handles the technical optimization of your site & assists with optimizing your content.","brand":{"@type":"Thing","name":"Yoast"},"offers":{"@type":"Offer","priceCurrency":"USD","price":"69.00"}}</script>
3+
Goede avond</script><hr><script type=application/ld+json>{"@context":"http://schema.org/","@type":"Product","name":"Yoast SEO for WordPress","image":"https://cdn-images.yoast.com/uploads/2010/10/Yoast_SEO_WP_plugin_FB.png","description":"Yoast SEO is the most complete WordPress SEO plugin. It handles the technical optimization of your site & assists with optimizing your content.","brand":{"@type":"Thing","name":"Yoast"},"offers":{"@type":"Offer","priceCurrency":"USD","price":"69.00"}}</script>

0 commit comments

Comments
 (0)