Skip to content

Commit b8cacf5

Browse files
committed
feat: add option to ignore minification of specific elements in CollapseWhitespace middleware
1 parent e69ba01 commit b8cacf5

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ protected $middleware = [
9292
- `RemoveComments::class`: Removes HTML, JS, and CSS comments from the output to reduce the transfer size of HTML files.
9393
- `CollapseWhitespace::class`: Reduces the size of HTML files by removing unnecessary white space.
9494
- **It automatically calls the `RemoveComments::class` middleware before executing.**
95+
- You can **ignore** minification of some elements. Add `data-tachyon-ignore` as an element attribute to do so.
9596
- `RemoveQuotes::class`: Removes unnecessary quotes from HTML attributes, resulting in a reduced byte count on most pages.
9697
- `ElideAttributes::class`: Reduces the transfer size of HTML files by removing attributes from tags if their values match the default attribute values.
9798
- `InsertDNSPrefetch::class`: Includes `<link rel="dns-prefetch" href="//www.example.com">` tags in the HTML `<head>` section to enable DNS prefetching, reducing DNS lookup time and improving page load times.

src/Middleware/CollapseWhitespace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function hideElements(string $buffer): string
8585
protected function findSkippedElements(string $buffer): void
8686
{
8787
foreach ($this->ignoreElements as $element) {
88-
$pattern = '/<' . $element . '[^>]*>(.*)<\/' . $element . '>/Uuis';
88+
$pattern = '/<' . $element . '[^>]*data-tachyon-ignore[^>]*|<' . $element . '[^>]*>(.*)<\/' . $element . '>/Uuis';
8989
if (preg_match_all($pattern, $buffer, $matches, PREG_SET_ORDER)) {
9090
foreach ($matches as $match) {
9191
$this->addSkippedElement($match[1]);

0 commit comments

Comments
 (0)