bvanhoekelen / php-compressor by Bart van Hoekelen

PHP compressor merge multiple css and js files into one file
157
7
3
Package Data
Maintainer Username: Bart van Hoekelen
Package Create Date: 2016-09-22
Package Last Update: 2018-12-18
Home Page:
Language: PHP
License: Apache-2.0
Last Refreshed: 2024-11-19 03:04:39
Package Statistics
Total Downloads: 157
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 7
Total Watchers: 3
Total Forks: 1
Total Open Issues: 0

PHP compressor

Hex.pm Packagist Prerelease Packagist Github issues Travis branch Travis branch Build: Master|Develop

Highlight

  • Merge several files into one file
  • Live compiler, fast and no additional program is needed
  • Allows user to write code that can be used in other projects » Code reuse
  • The ability to set variables » see variable in help
  • Support .css, .fcss and .js files
  • Required no changes on the live server
  • Reducing server load and client load time
  • Optimizing assets for a higher rank in google search results » PageSpeed
  • Easy to install » instalation
  • Support for Laravel framework » Laravel

Workflow

  • Input

    • Contains the building blocks
    • Folder can be placed before the public folder, no access for external users
    • For a better overview you can split easy your code in into several files
    • No @include, files are automatically merged
    • Ordering happened by name
  • Output

    • Each extension has its own file
    • Use normal html tag <link href='compressor/take.css' rel='stylesheet'> and <script src='compressor/take.js'></script> to grab it
  • PHP compressor run (PhpCompressor::run())

    • <loccation> (INPUT) directory where the .CSS, .FCSS and .JS files are
    • <destination> (OUTPUT) directory that contains the compressor/ folder. Note. de destination path is without the compressor/. This wil set in automatic
    • The output of PHP compressor wil set in the compressor/ folder as take.*
    • Run PHP compressor only in the developor environment, not in production!
    (Input)                                                           (Output)
    
Root/                                           .               Root/
└── Resources/             .. ..................;;.             └── Public/ (!)
    └── css/ (!)              .. PHP compresspr ;;;;.               └── compressor/ (static)
    │   ├── table.css    . . .::::::::::::::::::;;:'                   ├── take.css
    │   ├── alert.css                           :'                     └── take.js
    │   ├── button.css
    │   ...
    └── js/  (!)
    │   ├── table.js
    │   ├── alert.js
    │   ├── button.js
    │   ...
    ..

                             (PHP compressor)
 
 PhpCompressor::run(['resources/assets/css/', 'resources/assets/js/'], 'public/');
 PhpCompressor::run( [ <loccation> , <location>, ... ], <destination> ); // explanation!
    

Help, docs and links

Instalation

Install with Laravel

Get PHP compressor by running the composer command in the command line.

 $ composer require bvanhoekelen/php-compressor

Open the AppServiceProvider.php located in App\Providers\.

// Add namespace at the top
use PhpCompressor\PhpCompressor;

// Place the code in the `public function boot()`.
if(config('app.debug')) // DON'T USE ON PRODUCTION !!
    PhpCompressor::run(['resources/assets/css/', 'resources/assets/js/'], 'public/');

Place the code in <head> from the html file.

<!-- PHP compressor -->
<link href="{{ asset('/compressor/take.css') }}" rel="stylesheet">
<script src="{{ asset('/compressor/take.js') }}"></script>

Install with composer

Get PHP compressor by running the composer command in the command line.

 $ composer require bvanhoekelen/php-compressor

Run PHP compressor by place code before the view is draw.

// Require vender autoload
require_once('../vendor/autoload.php');

// Use namespace
use PhpCompressor\PhpCompressor;

// Switch which determines if environment is production
$production = false;

// Run php conpressor
if( ! $production ) // DON'T USE ON PRODUCTION !!
    PhpCompressor::run(['resources/css/', 'resources/js/'], 'public/');

Place the code in <head> from the html file.

<!-- PHP compressor -->
<link href='compressor/take.css' rel='stylesheet'>
<script src='compressor/take.js'></script>