Giter VIP home page Giter VIP logo

pecl-jsmin's Introduction

jsmin - PHP extension for JavaScript minification

Build Status

Introduction

This extension adds Douglas Crockford's jsmin functionality to PHP.

http://www.crockford.com/javascript/jsmin.html

Requirements

This extension currently works with PHP 7.0.0+. Use versions < 3.0 for PHP 5.X support.

Installation

Via PECL

You can install this extension by using the pecl command:

pecl install jsmin

Via source

To install via source, clone this repo and then run the following:

$ cd /path/to/source
$ phpize
$ ./configure
$ make install clean

Then, move the built module to your extensions directory.

Via Homebrew (OSX)

For those on OSX, you can use Homebrew to manage PHP versions. Included is the jsmin extension.

Take a look at Homebrew PHP for installation notes.

Thanks to Jon Whitcraft for pushing the definition for jsmin to the project.

Enable extension

You will want to enable the extension in php.ini by adding:

extension="jsmin.so"

Usage

Using jsmin is simple.

Function: jsmin

Use this function to minify JavaScript. It accepts a single string argument.

<?php

$javascript = <<<JS
/**
 * My JavaScript Library
 */

var notes = "jsmin is easy!";
JS;

echo jsmin($javascript);

Example output is the following:

var notes="jsmin is easy!";

You can also retrieve the latest error by passing by reference to the second argument:

jsmin($javascript, $error);

Function: jsmin_last_error

Returns error code of last call to jsmin().

Function: jsmin_last_error_msg

Returns an error message (string) for the last call to jsmin().

Constants

  • JSMIN_ERROR_NONE - No errors.
  • JSMIN_ERROR_UNTERMINATED_STRING - Unterminated string.
  • JSMIN_ERROR_UNTERMINATED_COMMENT - Unterminated comment.
  • JSMIN_ERROR_UNTERMINATED_REGEX - Unterminated regex.

Credits

Discovery Communications developed a similar extension in-house for minifying bundled JavaScript.

I decided to take the most recent source from Douglas Crockford's JSMin and port / manage the extension for PECL.

pecl-jsmin's People

Contributors

c9s avatar jan-e avatar rafallukawiecki avatar sqmk avatar weltling avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.