• Stars
    star
    305
  • Rank 136,879 (Top 3 %)
  • Language
    PHP
  • License
    GNU Lesser Genera...
  • Created about 15 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An easy to use stand-alone PHP-Library (but at the same time also a Wordpress plugin) that combines, optimizes, dataURI-fies, re-splits, compresses and caches your CSS and JS for quicker loading times.

CSS-JS-Booster

Copyright © 2010 Christian “Schepp” Schaefer
http://twitter.com/derSchepp

Functionality and Benefits

CSS-JS-Booster is a PHP-script that tries to automate as many performance
optimizing steps related to CSS and JS embedding as possible.

For CSS these steps are:

  • combine multiple CSS-files resulting in number of HTTP-requests going down
  • minify CSS
  • Embed any CSS-images smaller 24KB as data-URI or MHTML (for IE <= 7)
  • Split the output back into 2 even files that can load in parallel (not for WP)
  • GZIP-compress the resulting CSS
  • Have browsers cache the result as long as it remains unchanged
  • If IE6: Issue a JS-command to fix background image caching behaviour

For JS these steps are:

  • combine multiple JS-files resulting in number of HTTP-requests going down
  • Minify the JS through the Google Closure Compiler Webservice, or JSMin as fallback (not for WP)
  • GZIP-compress the resulting JS
  • Have browsers cache the result as long as it remains unchanged

+ GZIP-compresses the page calling those files.

Depending on the amount of CSS, CSS-images and JS, this can significantly
increase loading speed of your site.

Naah, your software stinks! Alternatives? Yes, there are!

Quite similar to this library is one called SmartOptimizer
with the major difference that it neither supports MHTML for the older IEs
nor does it offer the possibility to back-split the output into multiple
parts.

Then there is another nifty piece of software called Web Optimizer
that does what CSS-JS-Booster does, and a little lot more.
And there are many CMS-Plugins available. There exists a free and
a commercial version.

For any full-fledged web 3.0 company with money, their own servers and some
technical skills (or instead: even more money), there also exists an
enterprise-website-accelerator named aptimize

Just to have mentioned those…

System Requirements

CSS-JS-Booster absolutely requires PHP 5. No PHP 4, sorry…
Version-wise it is tested up until PHP 5.3.

Basic Usage

CSS-JS-Booster is a standalone-library as well as a Wordpress-plugin.
If you are interested in the Wordpress-part, you can skip all of this and
scroll further down to where you will find a Wordpress install guide.

Now, coming to the standalone-library…

CSS-JS-Booster is – as its name implies – divided into two function blocks:
A CSS-optimizing block and a JavaScript-optimizing block.

For both functionalities you first need to go into the booster-folder and
create a folder named booster_cache and have it CHMOD 0777.

Afterwards include

<?php 
include('booster/booster_inc.php'); 
$booster = new Booster();
?>

at the top of your (PHP-interpreted) file.
(Adjust the path according to your folder-structure)

Should you happen to only have static HTML-files, try enabling PHP-parsing
by putting a .htaccess-file into the site’s root with following directive:

AddType application/x-httpd-php .html .htm

For the CSS-part, put all releveant CSS-files into a subfolder css of your
site. Make sure, all declarations pointing to image-files have their paths
adjusted (i.e. all CSS should be fully functional by themselves inside that
folder).

If you have multiple CSS-files rename them so that they are alphabetically
sorted in the desired order, e.g.:

01_first.css
02_second.css
03_third.css

Then add this declaration in the HTML’s head-section:

<?php 
$booster->css_source = '../css'; //relative path from inside booster folder
echo $booster->css_markup(); 
?>

for example:

<head>
<title>Webpage</title>
<?php 
$booster->css_source = '../css'; //relative path from inside booster folder
echo $booster->css_markup(); 
?>
</head>

The argument is the path relativ to CSS-JS-Booster’s folder.

For the JS-part, put all releveant JS-files into a subfolder js of your
site.

If you have multiple JS-files rename them so that they are alphabetically
sorted in the desired order, e.g.:

01_first.js
02_second.js
03_third.js

Then add this declaration either in the HTML’s head-section, or – better for
performance and therefore recommended when you experience no errors – right
before the closing :

<?php 
$booster->js_source = '../js'; //relative path from inside booster folder
echo $booster->js_markup(); 
?>

for example:

<?php 
$booster->js_source = '../js'; //relative path from inside booster folder
echo $booster->js_markup(); 
?>
</body>
</html>

The argument is the path relativ to CSS-JS-Booster’s folder.

Notice: Don’t worry if on the very first call of your page your Javascript
doesn’t get loaded or your page takes long time to load. This is normal as
this is the delay caused by Google’s Closure compiler shrinking the scripts.
Once it has been successfully shrinked it won’t be shrinked again as long as
you do not change your Javascript.

Q & A for Advanced Usage

Q: How can I combine files out of multiple CSS- or JS-folders?
A: By setting as directory argument a comma delimited list of folders:

$booster->css_source = '../css_1,../css_2';
echo $booster->css_markup();

or an array

$booster->css_source = array('../css_1','../css_2');
echo $booster->css_markup();

The same holds true for JS:

$booster->js_source = '../js_1,../js_2';
echo $booster->js_markup();

or

$booster->js_source = array('../js_1','../js_2');
echo $booster->js_markup();

Q: I don’t want to have CSS-JS-Booster to pull all the files from inside a
directory, nor do I want to rename the files alphabetically. I rather want
full control over which files to use. Is this possible?

A: Yes. $booster->css_source and $booster->js_source are very flexible in
what they accept as source. You don’t need to specify a folder, you can
also specify a single file, or multiple files (either comma-separated or as
genuine array). Here are some examples:

$booster->css_source = '../css_1/reset.css,../css_1/base.css';
echo $booster->css_markup();

or as array

$booster->css_source = array('../css_1/reset.css','../css_1/base.css');
echo $booster->css_markup();

or files and folder mixed in an array:

$booster->css_source = array('../css_1/reset.css','../css_1/base.css','../css_2');
echo $booster->css_markup();

Q: I don’t want to have CSS-JS-Booster to pull files from anywhere at all.
I rather want to pass it a CSS-/Javascript-string and have that optimized.
Is this possible?

A: Yes, $booster->css_source and $booster->js_source can now also accept
code-strings as source. But you have to switch the respective booster-part to
stringmode before by setting $booster->css_stringmode = TRUE; or
$booster->js_stringmode = TRUE;. Here is an example:

$booster = new Booster();
$booster->css_stringmode = TRUE;
$booster->css_source = '.div1 {
	display: block;
	width: 400px;
}';
echo $booster->css(); 

Q: For CSS and JS tags, can I have its output-markup in HTML 4.01 fashion?
A: No problem, do this:

$booster->markuptype = 'HTML';
echo $booster->css_markup();

or

$booster->markuptype = 'HTML';
echo $booster->js_markup();

Q: Can I stop CSS-JS-Booster to cleanup the cache folder on sundays?
A: Yes, just configure this:

$booster->booster_cachedir_autocleanup = FALSE;

Q: For CSS, how can I define a different/specific target-medium?
A: By setting the desired media before echoing the markup:

$booster->css_media = 'screen,projection';
echo $booster->css_markup();

Q: For CSS, can I define a second folder to feed an alternate stylesheet?
A: Sure, e.g. like this:

$booster->css_source = 'css_1';
echo $booster->css_markup();
//
$booster->css_source = 'css_2';
$booster->css_rel = 'alternate stylesheet';
$booster->css_title = 'Alternate Stylesheet';
echo $booster->css_markup();

Q: For CSS, can I influence in how many even parts it gets split?
A: Nothing easier than this:

$booster->css_totalparts = 4;
echo $booster->css_markup();

Q: I would like to have YUI Compressor to minify my CSS locally. Is that
possible?

A: Yes, it is possible, as long as you have a dedicated server with Java
installed:

$booster->css_hosted_minifier = TRUE;
echo $booster->css_markup();

Please note that this feature is still alpha and possibly buggy!

Q: The JS-minification seems to break my scripts. Can I disable it?
A: Yes, you can:

$booster->js_minify = FALSE;
echo $booster->js_markup();

Q: The JS-minification through the Google webservice takes too long.
Can I have a local Google Closure minifier instead?

A: Yes, you can, as long as you have a dedicated server with Java installed:

$booster->js_hosted_minifier = TRUE;
echo $booster->js_markup();

Please note that this feature is still alpha and possibly buggy!

Q: I would like to make use of the async and/or defer attributes for JS.
Is there a way to enable them?

A: Yes, you can set the mode easily. Just remember that when Booster detects
any document.write inside your script, it will ommit those attributes.

This will set the async, and as fallback for older browsers defer attribute:

$booster->js_executionmode = "async";
echo $booster->js_markup();

This will set the defer attribute:

$booster->js_executionmode = "defer";
echo $booster->js_markup();

Please note: if CSS-JS-Booster detects a document.write inside JavaScript
it will omit async and defer as both conflict with document.write.

Q: I would like to make use of the onload attribute for JS (like for example
together with the async and/or defer attributes). How?

A: This will fill the onload attribute with the function “initialize();”:

$booster->js_onload = "initialize();";
echo $booster->js_markup();

Q: I need to debug CSS (e.g. in Firebug) or JS in the console – but I cannot
find anything due to dataURI-fication and minification…

A: Yes, that’s hard. In this case turn debug-mode on before outputting:

$booster->debug = TRUE;
echo $booster->css_markup();
echo $booster->js_markup();

Q: Can I have CSS with big inlined images lazyload on DOM ready?
A: Yes, just set the following parameter:

$booster->css_lazyload = TRUE;

In an ideal way you would split your image-heavy CSS apart from your normal CSS
and just load that one later:

$booster = new Booster();
$booster->css_source = 'styles_without_images.css';
echo $booster->css_markup();
$booster->css_source = 'styles_with_images.css';
$booster->css_lazyload = TRUE;
echo $booster->css_markup();

.htaccess Acceleration

For an even further speed-boost, either add the contents of

/htaccess/.htaccess

to your existing .htaccess-file in your site’s root, or the file itself
shouldn’t you have any .htaccess-file installed in your site’s root yet.

Should you happen to get internal server error 500s, then something went
wrong with my .htaccess and you server-config.

What the .htaccess adds on top:

  • Turns off ETags
  • Adds aggressive caching for all sort of assets like images/favicon/flash

Wordpress Plugin

CSS-JS-Booster also works as a Wordpress plugin.

Installation

  • Copy the whole booster folder into wp-content/plugins/
  • Create a subfolder booster_cache inside wp-content/plugins/booster/ and CHMOD it to 0777 (write-permissions)
  • Go into the admin-panel to the plugins and activate “CSS-JS-Booster”
  • Copy the contents of the file htaccess/.htaccess and append them to the contents of the .htaccess-file in the root of your Wordpress-site

Compatibility with other plugins

CSS-JS-Booster may in rare cases break some other plugins.
I noticed for example that plugins trying to calculate file-paths based on the src-attribute of the script-tag break.
So you need to check yourself.

Copyright and License Information for 3rd party elements used in the scripts

JSMin is origined from here:
http://www.crockford.com/javascript/jsmin.html

YUI Compressor comes from here:
http://developer.yahoo.com/yui/compressor/
All code specific to YUI Compressor is issued under a BSD license.

Google Closure Compiler originates from here:
http://code.google.com/intl/de-DE/closure/compiler/
Licensed under the Apache License, Version 2.0 (the “License”);

Copyright and License Information for 3rd party elements used in example1

HTML and CSS Template named “Blog Division” is taken from here:
http://www.free-css.com/free-css-templates/page1/blog-division.php
You find its license inside example1’s root-folder

The Sansation Font is © 2008 Bernd Montag and taken from here:
http://www.free-css.com/free-css-templates/page1/blog-division.php
You find its license inside example1’s js-folder

cufon has its home here:
http://github.com/sorccu/cufon
You find its license inside example1’s js-folder

jQuery is taken from here:
http://code.google.com/p/jqueryjs/
You find its license inside example1’s js-folder

More Repositories

1

box-sizing-polyfill

A CSS box-sizing: border-box polyfill for IE 6/7
1,177
star
2

CSS-Filters-Polyfill

This polyfill takes the official CSS filters syntax and translates it to the different equivalent techniques that the browsers know for those effects
JavaScript
761
star
3

dom-treemap-devtools-extension

A Chrome Devtools extension that helps you explore the distribution of DOM nodes in the document tree.
JavaScript
76
star
4

HTTP-headers

Every call we send to and receive from a web server is accompanied by more or less metadata, also known as the HTTP headers. Usually, those headers stay hidden in the shadows and we barely notice them - and we underestimate their powers. But ignoring them is a mistake! There is a lot happening around them lately. During The last couple of years a lot of new and powerful headers have emerged which, when applied correctly, help us harden our web applications against attacks and make our sites load a lot faster. That's why in this talk, I'm gonna give you the modern take on how to make the web more secure & fast.
HTML
29
star
5

CSS-Parser

A nice litte css parser written in php
PHP
19
star
6

async-document.write

Patches document.write to execute in a non-blocking way.
JavaScript
17
star
7

connection-type-checker

Utility that tries to figure out if you are on cellular or broadband
JavaScript
12
star
8

CSS-Prefix-Spawner

Tired of having to repeat all vendor prefixes over and over again just for getting your cross-browser dosis of CSS 3 eyecandy? Bother no more, my friend! Paste your single-vendor CSS or point to the file and we will automatically add the rest.
PHP
12
star
9

SASS-Mixins

9
star
10

IMG-2-TABLE

PHP-Script that converts GIF, PNG and JPG images to a TABLE-markup reproducing the image. Good for embedding images non-blockable inside HTML-emails. The lower the color-count the better for resulting code-size!
PHP
4
star
11

native-browser-apis

In this talk, I will give you an overview on how far native browser APIs have matured, thus freeing our sites from the grips of jQuery, lodash and other helper libraries. We will look at working more elegantly with arrays and objects in JavaScript, at modern DOM traversal and manipulation possibilities, at event delegation, at native smooth scrolling, look at ways to build carousels without library, we will explore built-in tools for image and font lazy loading, and we will bury DOMContentLoaded forever.
HTML
4
star
12

Chroma-Corners

“Chroma Corners” is the name of a new technique to create rounded corners in IE 6 – 8. It uses IE’s chroma-filter as a tool to mask away corner areas, which are created as a graphic and which are filled with a solid color. It is and behaves like standard HTML + CSS as opposed to the newer VML-based approches. It gives you more freeness and needs less photoshopping work than older background image based techniques for rounded corners like “Mountain Top” or “Sliding Doors”.
PHP
4
star
13

grunt-compile-revealjs

Compiles reveal.js slide decks from a JSON configuration and HTML partials
JavaScript
3
star
14

HTML5-Canvas-Workshop

JavaScript
3
star
15

crx-submit-to-workingdraft-trello

Chrome extension for submitting links to our podcast's board on Trello
JavaScript
3
star
16

making-of-rp-online

Nachrichtenseiten im Jahre 2020: Making of RP ONLINE
JavaScript
3
star
17

grunt-spreadsheet-to-json

Takes a Google Spreadsheet with translations and generates multiple JSON files from the columns.
JavaScript
2
star
18

CSS-JS-Booster-Website

PHP
2
star
19

schepp.dev

My personal site
Nunjucks
2
star
20

prototyping-for-performance

Performance-Experimente mit Chrome Devtools und CloudFlare Workers
JavaScript
2
star
21

Turbine-Extras

Additional files extending the capabilities of Turbine
PHP
2
star
22

HTTP-2

20 years have passed since the IETF introduced HTTP/1.1. At the time web pages were still designed with tables and font tags and they had hardly more than four images per page in total. HTTP/1.1 was perfectly suited to this application scenario. For today's projects, however, HTTP/1.1 is a massive bottleneck. To compensate for its conceptual disadvantages, we developed build processes in which we bundle resources via concatenation, inlining or spriting. In addition, we rely on concepts such as domain sharing and cookieless domains. The good news is: HTTP/2 has arrived and puts an end to the disadvantages of its predecessor. And it is supported by all modern browsers. But it's not enough to just flip a switch. We need to rethink and throw established processes and concepts overboard if we are to get the most out of HTTP/2.
CSS
2
star
23

imagery-on-the-web

Using images on a website is pretty straightforward, right? It's using an <img> element or a CSS background and then have them display a JPG, PNG or SVG. And that's it. Or is there more to it than that? Well, yes, there is. And it's a truckload full of possibilities.
HTML
2
star
24

webtechnologie-gluecksrad

Das Working Draft Webtechnologie GlĂĽcksrad
JavaScript
1
star
25

grunt-sass-recursive-import

Recursively includes SASS Partials in all Subdirectories
JavaScript
1
star
26

a-property-to-unlock-the-world

A Talk on why CSS Houdini is dead, but `@property` is not.
HTML
1
star
27

HTML5-WPO-Slides

Slidedeck for the HTML5 Days 2014 in Munich
PHP
1
star
28

css-next

After Grid and Flexbox CSS seems to have lost most of its dynamic. The most urgent layout problems seem to be solved and all eyes turn to JavaScript, because that's where all the exciting things seem to happen at the moment. But is CSS really "feature complete"? And does this development standstill really exist? To find that out, we first search for recently implemented CSS properties. Maybe we will find some after all? Then we take a look into the W3C's CSS crystal ball to see if there are some exciting things planned for the future.
JavaScript
1
star
29

wwnrw

Website of the Webworkers NRW meetup
HTML
1
star