PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Bennett Stone   MagicMin   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: MagicMin
Merge and minify and JavaScript and CSS files
Author: By
Last change: Updated to 2.7. Seriously simplified config extension to allow easier future expansion. Updated readme.
Date: 8 years ago
Size: 3,802 bytes


Class file image Download
 * example.php
 * Demonstrates compression functions and minification usage
 * for stylesheets and javascript files
 * @author Bennett Stone
 * @version 2.5
 * @date 02-Jun-2013
 * @updated 15-Jun-2013
 * @package MagicMin

//Include the caching/minification class
require( 'class.magic-min.php' );

//Initialize the class with image encoding, gzip, a timer, and use the google closure API
$vars = array(
'encode' => true,
'timer' => true,
'gzip' => true,
'closure' => true,
'remove_comments' => false
$minified = new Minifier( $vars );
<!DOCTYPE html>
<html xmlns="" xml:lang="EN" lang="EN" dir="ltr">
<head profile="">
    <title>Example Usage | Caching and Minification Class</title>

    <!--Output a new merged stylesheet with only the $included_styles included in order-->
    $included_styles = array(
    <link rel="stylesheet" href="<?php $minified->merge( 'css/awesome.min.css', 'css', $included_styles ); ?>" />
    <!--Output a default minified stylesheet: will output as css/bootstrap.min.css-->
    <link rel="stylesheet" href="<?php $minified->minify( 'css/bootstrap.css' ); ?>" />
    <!--Output a minified javascript file with completely different name, and ?v=1.8 param-->
    <script src="<?php $minified->minify( 'js/jquery.reveal.js', 'js/jquery-magicreveal.min.js', '1.8' ); ?>"></script>

    <!--Retrieve the contents of all javascript files in the /js directory as master.min.js (excluding a couple AND making sure bootstrap and validate are first and second)-->
    $exclude = array(
    $prioritize = array(
    <script src="<?php $minified->merge( 'js/packed.min.js', 'js', 'js', $exclude, $prioritize ); ?>"></script>

    <!--Get all the stylesheets in a directory and make a single minified stylesheet (excluding the ones used above)-->
    $exclude_styles = array(
    <link rel="stylesheet" href="<?php $minified->merge( 'css/master.min.css', 'css', 'css', $exclude_styles ); ?>" />

    <!--Get all the stylesheets in the /base directory and compile them-->
    <link rel="stylesheet" href="<?php $minified->merge( 'css/base/bennett-min.css', 'css/base', 'css' ); ?>" />

    <!--Include ONLY a specified list of files IN ORDER-->
    $include_only = array(
    <script src="<?php $minified->merge( 'js/compressor.min.js', 'js', $include_only ); ?>"></script>


    <a href="#" class="new-modal">Click Me For A Modal</a>

    <div id="myModal" class="reveal-modal">
         <h1>Modal Title</h1>
         <p>Any content could go in here.</p>
         <a class="close-reveal-modal">&#215;</a>

    <textarea name="whatever"></textarea>

    <script type="text/javascript">
    jQuery(document).ready(function($) {
         $('.new-modal').click(function(e) {

//Output actions associated with the minification to the console