Comments (2)
For the moment:
- Create new Middleware and extends \RenatoMarinho\LaravelBladeMinify\Middleware\Minify
- Override the html function with:
public function html($response)
{
$buffer = $response->getContent();
$replace = [
'/<!--[^\[](.*?)[^\]]-->/s' => '',
"/<\?php/" => '<?php ',
"/\n([\S])/" => '$1',
"/\r/" => '',
"/\n/" => '',
"/\t/" => '',
"/ +/" => ' ',
"/> +</" => '><',
];
if(strpos($buffer,'<pre>') !== false) {
$replace = [
'/<!--[^\[](.*?)[^\]]-->/s' => '',
"/<\?php/" => '<?php ',
"/\r/" => '',
"/>\n</" => '><',
"/>\s+\n</" => '><',
"/>\n\s+</" => '><',
];
}
$buffer = preg_replace(array_keys($replace), array_values($replace), $buffer);
if(!($response instanceof BinaryFileResponse)) {
$response->setContent($buffer);
}
return $response;
}
For example:
I created new Middleware called MinifyHTML:
<?php
namespace App\Http\Middleware;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class MinifyHTML extends \RenatoMarinho\LaravelBladeMinify\Middleware\Minify
{
/**
* @param $response
* @return mixed
*/
public function html($response)
{
$buffer = $response->getContent();
$replace = [
'/<!--[^\[](.*?)[^\]]-->/s' => '',
"/<\?php/" => '<?php ',
"/\n([\S])/" => '$1',
"/\r/" => '',
"/\n/" => '',
"/\t/" => '',
"/ +/" => ' ',
"/> +</" => '><',
];
if (strpos($buffer, '<pre>') !== false) {
$replace = [
'/<!--[^\[](.*?)[^\]]-->/s' => '',
"/<\?php/" => '<?php ',
"/\r/" => '',
"/>\n</" => '><',
"/>\s+\n</" => '><',
"/>\n\s+</" => '><',
];
}
$buffer = preg_replace(array_keys($replace), array_values($replace), $buffer);
if (!($response instanceof BinaryFileResponse)) {
$response->setContent($buffer);
}
return $response;
}
}
And replace in Kernel.php \RenatoMarinho\LaravelBladeMinify\Middleware\Minify::class to MinifyHTML::class
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
MinifyHTML::class,
];
from laravel-page-speed.
Yes, I'm getting error when show pdf file.
from laravel-page-speed.
Related Issues (20)
- InlineCss misses space and thus breaks styles
- Issue with Pre tag HOT 1
- Laravel 9.0 HOT 3
- Conflict with other packages HOT 1
- Livewire not working well with this package. HOT 7
- dont run script file
- Uri's in JS stripped of double slash
- LARAVEL 9 Code Debug Screen Not Showing After Enable Page speed HOT 2
- Suggestion: There is any way to prevent code block to being minify.
- Compatibility issue with Laravel 10 HOT 9
- DeferJavascript causes "Uncaught ReferenceError: GLightbox is not defined" HOT 1
- ~
- Compatible Laravel 10 Please Fix composer json
- Works incorrectly with JSON schema
- CollapseWhitespace class is showing blank page HOT 1
- install with laravel 10 HOT 7
- Comment do not get removed if Page source is Lengthy
- I am using Laravel 8 and getting Blank white page from "CollapseWhitespace" class HOT 1
- 🐞 Bug `RemoveComments` + `CollapseWhitespace` - Correctly handle `//` JS comments
- Laravel 11 out of the oven HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-page-speed.