Skip to content

Commit

Permalink
docs: finish readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
fahlisaputra committed Jul 19, 2023
1 parent f4c47aa commit 3023a07
Showing 1 changed file with 115 additions and 12 deletions.
127 changes: 115 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Laravel Minify is a package for minifying and obfuscating Javascript, CSS, HTML and Blade template files. It runs automatically when you load a page or view. This package can minify entire response and also can minify blade at compile time.

<p align="center">
<p align="left">
<a href="https://packagist.org/packages/fahlisaputra/laravel-minify"><img src="http://poser.pugx.org/fahlisaputra/laravel-minify/v" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/fahlisaputra/laravel-minify"><img src="http://poser.pugx.org/fahlisaputra/laravel-minify/downloads" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/fahlisaputra/laravel-minify"><img src="http://poser.pugx.org/fahlisaputra/laravel-minify/license" alt="License"></a>
Expand All @@ -23,12 +23,21 @@ Laravel Minify is a package for minifying and obfuscating Javascript, CSS, HTML
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Laravel Minify</title>
<style>
h2 {
color: red;
background-color: yellow;
}
</style>
</head>
<body>
<h2>JavaScript Numbers</h2>
<p>Number can be written with or without decimals.</p>
<p id="demo"></p>
<script src="{{ MinifyAsset('js/test.js') }}"></script>
<h2>Laravel Minify</h2>
<p>Laravel Minify is a package for minifying and obfuscating Javascript, CSS, HTML and Blade template files.</p>
<script>
function helloWorld() {
alert('Hello World');
}
</script>
</body>
</html>
```
Expand All @@ -37,24 +46,24 @@ Laravel Minify is a package for minifying and obfuscating Javascript, CSS, HTML

```html
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Laravel Minify</title></head><body><h2>JavaScript Numbers</h2><p>Number can be written with or without decimals.</p><p id="demo"></p><script src="_minify/js/test.js"></script></body></html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Laravel Minify</title><style>h2{color:red;;background-color:yellow;}</style></head><body><h2>Laravel Minify</h2><p>Laravel Minify is a package for minifying and obfuscating Javascript, CSS, HTML and Blade template files.</p><script>eval(((_,__,___,____,_____,______,_______)=>{______[___](x=>_______[__](String[____](x)));return _______[_](_____)})('join','push','forEach','fromCharCode','',[102,117,110,99,116,105,111,110,32,104,101,108,108,111,87,111,114,108,100,40,41,123,97,108,101,114,116,40,39,72,101,108,108,111,32,87,111,114,108,100,39,41,125],[]));</script></body></html>
```

#### Javascript Obfuscate
- Before Obfuscate

```javascript
function myFunction() {
var x = 999999999999999;
var y = 9999999999999999;
document.getElementById("demo").innerHTML = x + "<br>" + y;
function helloWorld() {
const number1 = 5;
const number2 = 10;
alert('Hello World! ' + (number1 + number2));
}
```

- After Obfuscate

```javascript
eval(((_,__,___,____,_____,______,_______)=>{______[___](x=>_______[__](String[____](x)));return _______[_](_____)})('join','push','forEach','fromCharCode','',[102,117,110,99,116,105,111,110,32,109,121,70,117,110,99,116,105,111,110,40,41,123,118,97,114,32,120,61,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,59,118,97,114,32,121,61,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,59,100,111,99,117,109,101,110,116,46,103,101,116,69,108,101,109,101,110,116,66,121,73,100,40,34,100,101,109,111,34,41,46,105,110,110,101,114,72,84,77,76,61,120,43,34,60,98,114,62,34,43,121,125],[]));
eval(((_,__,___,____,_____,______,_______)=>{______[___](x=>_______[__](String[____](x)));return _______[_](_____)})('join','push','forEach','fromCharCode','',[102,117,110,99,116,105,111,110,32,104,101,108,108,111,87,111,114,108,100,40,41,123,99,111,110,115,116,32,110,117,109,98,101,114,49,61,53,59,99,111,110,115,116,32,110,117,109,98,101,114,50,61,49,48,59,97,108,101,114,116,40,39,72,101,108,108,111,32,87,111,114,108,100,33,32,39,43,40,110,117,109,98,101,114,49,43,110,117,109,98,101,114,50,41,41,125],[]));
```


Expand All @@ -76,7 +85,101 @@ $ php artisan vendor:publish --provider="Fahlisaputra\Minify\MinifyServiceProvid

This will create a config/minify.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

## Register the Middleware
In order Laravel Minify can intercept your request to minify and obfuscate, you need to add the Minify middleware to the `app/Http/Kernel.php` file:

```php
protected $middleware = [
....
// Middleware to minify html
\Fahlisaputra\Minify\Middleware\MinifyCss::class,
// Middleware to minify css
\Fahlisaputra\Minify\Middleware\MinifyJavascript::class,
// Middleware to minify javascript
\Fahlisaputra\Minify\Middleware\MinifyHtml::class,
];
```
You can choose which middleware you want to use. Put all of them if you want to minify html, css, and javascript at the same time.

## Usage
This is how you can use Laravel Minify in your project.
### Enable Minify
You can enable minify by setting `minify` to `true` in the `config/minify.php` file. For example:

```php
"enabled" => env("MINFY_ENABLED", true),
```

### Minify Asset Files
You must set `true` on `assets_enabled` in the `config/minify.php` file to minify your asset files. For example:

```php
"assets_enabled" => env("MINFY_ASSETS_ENABLED", true),
```

You can minify your asset files by using the `minify()` helper function. This function will minify your asset files and return the minify designed route. In order to work properly, you need to put your asset files in the `resources/js` or `resources/css` directory. For example:

```html
<link rel="stylesheet" href="{{ minify('/css/test.css') }}">
```

where `test.css` is located in the `resources/css` directory.

```html
<script src="{{ minify('/js/test.js') }}"></script>
```

where `test.js` is located in the `resources/js` directory.

### Automatic Insert Semicolon on Javascript or CSS
You can enable automatic insert semicolon on javascript or css by setting `true` on `insert_semicolon` in the `config/minify.php` file. For example:

```php
"insert_semicolon" => [
'css' => env("MINIFY_CSS_SEMICOLON", true),
'js' => env("MINIFY_JS_SEMICOLON", true),
],
```
Please note: this feature is still experimental. It may not work properly and may cause errors to your javascript or css.

### Skip Minify on Blade
You can skip minify on blade by using attribute `ignore--minify` inside script or style tag. For example:

```html
<style ignore--minify>
/* css */
</style>

<script ignore--minify>
/* javascript */
</script>
```

### Skip Minify when Rendering View
You can skip minify when rendering view by passing `ignore_minify = true` in the view data. For example:

```php
return view('welcome', ['ignore_minify' => true]);
```

### Skip Minify by Route
You can skip minify by route by adding the route name to the `ignore` array in the `config/minify.php` file. For example:

```php
"ignore" => [
'/admin'
],
```
## License
Laravel Minify is licensed under the [MIT license](LICENSE).

## Credits
- [Fahli Saputra](https://github.com/fahlisaputra)
- [:D](https://github.com/dz-id)
- [Spentura](https://spentura.com)

## Support
If you are having general issues with this package, feel free to contact us on [saputra@fahli.net](mailto:saputra@fahli.net)

[MIT](LICENSE) (MIT)
## Report Vulnerability
Please read [our security policy](https://github.com/fahlisaputra/laravel-minify/security/policy) for more details.

0 comments on commit 3023a07

Please sign in to comment.