Skip to content

Commit

Permalink
Added minify for css/js [#1 status:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Leveille committed Jan 28, 2009
1 parent 2bc204d commit 3d94fcb
Show file tree
Hide file tree
Showing 47 changed files with 4,892 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ Serializer/*.ser
*.log
*.tmp*
.project
cache/minify_*
8 changes: 4 additions & 4 deletions smc/config/config.ini.php
Expand Up @@ -3,13 +3,13 @@
date_default_timezone_set('America/New_York'); //http://us3.php.net/manual/en/timezones.america.php
define("ROOT", dirname(dirname(dirname(__FILE__)))); //path to site root, relative to this config file
define("SMC_REL", '/smc');
define("SMC_DEMO_REL", SMC_REL . '/tmp/demo'); //the name of your simplemc directory. This will likely not change
define("SMC_DEMO_REL", SMC_REL . '/tmp/demo'); //the name of your simplemc directory. This will likely not change
define("SMC_CACHE_ENABLED", false); //turn on caching for content blocks?
define('SMC_DEBUG_MODE', true); //Debug mode will serve full CSS/JavaScript files, and will always show errors
define('SMC_DEBUG_MODE', false); //Debug mode will serve full CSS/JavaScript files, and will always show errors
define('SMC_IE_DEBUG', false); //turn on debugging for javascript in IE
define('SMC_SHOW_ERRORS', true); //show errors (this should only be turned on in development, and never (well, most of the time) in production)
define('SMC_SHOW_ERRORS', false); //show errors (this should only be turned on in development, and never (well, most of the time) in production)
define('SMC_LOG_ERRORS', false); //should errors be logged? If so, logs are written to tmp/logs/errors.log
define("SMC_THEME", 'gray'); //the name of the theme to apply
define('SMC_MINIFY_ENABLED', true); //should minify be enabled (see: http://code.google.com/p/minify/)

//what doctype will you be serving your pages in? Default is HTML 4.01 Strict. Options include:
/*
Expand Down
20 changes: 13 additions & 7 deletions smc/core/admin/index.php
Expand Up @@ -8,13 +8,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple MC Content Management</title>

<?php if(defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE): ?>
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/ext-all.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/xtheme-<?php echo SMC_THEME; ?>.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_ADMIN_REL; ?>/stylesheets/screen.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_CSS_REL; ?>/fck_content.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<?php if((defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE) ||
(defined('SMC_MINIFY_ENABLED') && !SMC_MINIFY_ENABLED)): ?>
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/ext-all.css" rel="stylesheet" type="text/css" media="screen">
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/xtheme-gray.css" rel="stylesheet" type="text/css" media="screen">
<link href="<?php echo SMC_ADMIN_REL; ?>/stylesheets/screen.css" rel="stylesheet" type="text/css" media="screen">
<link href="<?php echo SMC_CSS_REL; ?>/fck_content.css" rel="stylesheet" type="text/css" media="screen">
<?php else: ?>
<!-- Serve minified css -->
<link href="<?php echo SMC_MINIFY_REL; ?>/min/g=cssadmin" rel="stylesheet" type="text/css" media="screen">
<?php endif; ?>
</head>
<body scroll="no">
Expand Down Expand Up @@ -59,14 +61,16 @@
<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
<?php endif; ?>

<?php if(defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE): ?>
<?php if((defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE) ||
(defined('SMC_MINIFY_ENABLED') && !SMC_MINIFY_ENABLED)): ?>
<script type="text/javascript" src="<?php echo SMC_EXT_REL; ?>/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<?php echo SMC_EXT_REL; ?>/ext-all.js"></script>
<script type="text/javascript" src="<?php echo SMC_JAVASCRIPTS_REL; ?>/auth.js"></script>
<script type="text/javascript" src="<?php echo SMC_ADMIN_REL; ?>/state/SessionProvider.js"></script>
<script type="text/javascript" src="<?php echo SMC_FCK_REL; ?>/fckeditor.js"></script>
<?php else: ?>
<!-- Implement js minify -->
<script type="text/javascript" src="<?php echo SMC_MINIFY_REL; ?>/min/?g=jsadmin_1"></script>
<?php endif; ?>

<script type="text/javascript" src="<?php echo sprintf('%s/state/save-state.php', SMC_ADMIN_REL); ?>"></script>
Expand Down Expand Up @@ -115,14 +119,16 @@
-->
</script>

<?php if(defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE): ?>
<?php if((defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE) ||
(defined('SMC_MINIFY_ENABLED') && !SMC_MINIFY_ENABLED)): ?>
<script type="text/javascript" src="<?php echo SMC_ADMIN_REL; ?>/javascripts/TabCloseMenu.js"></script>
<script type="text/javascript" src="<?php echo SMC_ADMIN_REL; ?>/javascripts/AdminLayout.js"></script>
<script type="text/javascript" src="<?php echo SMC_ADMIN_REL; ?>/javascripts/AdminPanel.js"></script>
<script type="text/javascript" src="<?php echo SMC_ADMIN_REL; ?>/javascripts/ContentGrid.js"></script>
<script type="text/javascript" src="<?php echo SMC_ADMIN_REL; ?>/javascripts/MainPanel.js"></script>
<?php else: ?>
<!-- Implement js minify -->
<script type="text/javascript" src="<?php echo SMC_MINIFY_REL; ?>/min/?g=jsadmin_2"></script>
<?php endif; ?>
</body>

Expand Down
1 change: 1 addition & 0 deletions smc/core/bootstrap.php
Expand Up @@ -21,6 +21,7 @@
define("SMC_INCLUDES", SMC_CORE . '/support/includes');
define("SMC_HTML_PURIFIER", SMC_VENDORS . '/htmlpurifiersa');
define("SMC_MINIFY", SMC_VENDORS . '/minify');
define("SMC_MINIFY_REL", SMC_VENDORS_REL . '/minify');

/*
* Set include path to include paths to classes and bai_cms includes
Expand Down
5 changes: 3 additions & 2 deletions smc/core/support/includes/smc_javascripts.inc.php
Expand Up @@ -5,14 +5,15 @@
<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
<?php endif; ?>

<?php if(defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE): ?>
<?php if((defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE) ||
(defined('SMC_MINIFY_ENABLED') && !SMC_MINIFY_ENABLED)): ?>
<script type="text/javascript" src="<?php echo SMC_EXT_REL; ?>/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<?php echo SMC_EXT_REL; ?>/ext-all.js"></script>
<script type="text/javascript" src="<?php echo SMC_FCK_REL; ?>/fckeditor.js"></script>
<script type="text/javascript" src="<?php echo SMC_JAVASCRIPTS_REL; ?>/smc.js"></script>
<script type="text/javascript" src="<?php echo SMC_JAVASCRIPTS_REL; ?>/auth.js"></script>
<?php else: ?>
<!-- Implement js minify -->
<script type="text/javascript" src="<?php echo SMC_MINIFY_REL; ?>/min/?g=jsfront"></script>
<?php endif; ?>

<script>
Expand Down
3 changes: 2 additions & 1 deletion smc/core/support/includes/smc_stylesheets.inc.php
Expand Up @@ -3,11 +3,12 @@

<?php if(defined('SMC_DEBUG_MODE') && SMC_DEBUG_MODE): ?>
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/ext-all.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/xtheme-<?php echo SMC_THEME; ?>.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_EXT_REL; ?>/resources/css/xtheme-gray.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_CSS_REL; ?>/admin.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<link href="<?php echo SMC_CSS_REL; ?>/fck_content.css" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<?php else: ?>
<!-- Serve minified css -->
<link href="<?php echo SMC_MINIFY_REL; ?>/min/?g=cssfront" rel="stylesheet" type="text/css" media="screen"<?php echo SMC_CLOSE_TAG; ?>>
<?php endif; ?>

<!--[if IE]>
Expand Down
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions smc/core/vendors/minify/LICENSE.txt
@@ -0,0 +1,26 @@
Copyright (c) 2008 Ryan Grove <ryan@wonko.com>
Copyright (c) 2008 Steve Clay <steve@mrclay.org>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of this project nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions smc/core/vendors/minify/min/.htaccess
@@ -0,0 +1,4 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([a-z]=.*) index.php?$1 [L,NE]
</IfModule>
120 changes: 120 additions & 0 deletions smc/core/vendors/minify/min/README.txt
@@ -0,0 +1,120 @@
The files in this directory represent the default Minify setup designed to ease
integration with your site. This app will combine and minify your Javascript or
CSS files and serve them with HTTP compression and cache headers.


RECOMMENDED

It's recommended to edit config.php to set $min_cachePath to a writeable
(by PHP) directory on your system. This will improve performance.


GETTING STARTED

The quickest way to get started is to use the Minify URI Builder application
on your website: http://example.com/min/builder/


MINIFYING A SINGLE FILE

Let's say you want to serve this file:
http://example.com/wp-content/themes/default/default.css

Here's the "Minify URL" for this file:
http://example.com/min/?f=wp-content/themes/default/default.css

In other words, the "f" argument is set to the file path from root without the
initial "/". As CSS files may contain relative URIs, Minify will automatically
"fix" these by rewriting them as root relative.


COMBINING MULTIPLE FILES IN ONE DOWNLOAD

Separate the paths given to "f" with commas.

Let's say you have CSS files at these URLs:
http://example.com/scripts/jquery-1.2.6.js
http://example.com/scripts/site.js

You can combine these files through Minify by requesting this URL:
http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js


SIMPLIFYING URLS WITH A BASE PATH

If you're combining files that share the same ancestor directory, you can use
the "b" argument to set the base directory for the "f" argument. Do not include
the leading or trailing "/" characters.

E.g., the following URLs will serve the exact same content:
http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js,scripts/home.js
http://example.com/min/?b=scripts&f=jquery-1.2.6.js,site.js,home.js


MINIFY URLS IN HTML

In (X)HTML files, don't forget to replace any "&" characters with "&amp;".


SPECIFYING ALLOWED DIRECTORIES

By default, Minify will serve any *.css/*.js files within the DOCUMENT_ROOT. If
you'd prefer to limit Minify's access to certain directories, set the
$min_serveOptions['minApp']['allowDirs'] array in config.php. E.g. to limit
to the /js and /themes/default directories, use:

$min_serveOptions['minApp']['allowDirs'] = array('//js', '//themes/default');


GROUPS: FASTER PERFORMANCE AND BETTER URLS

For the best performance, edit groupsConfig.php to pre-specify groups of files
to be combined under preset keys. E.g., here's an example configuration in
groupsConfig.php:

return array(
'js' => array('//js/Class.js', '//js/email.js')
);

This pre-selects the following files to be combined under the key "js":
http://example.com/js/Class.js
http://example.com/js/email.js

You can now serve these files with this simple URL:
http://example.com/min/?g=js


GROUPS: FAR-FUTURE EXPIRES HEADERS

Minify can send far-future (one year) Expires headers. To enable this you must
add a number to the querystring (/min/?g=js&1234) and alter it whenever a
source file is changed. If you have a build process you can use a build/
source control revision number. If not, the utility function Minify_groupUri()
will return "versioned" Minify URIs for use in your HTML. E.g.:

<?php
// add /min/lib to your include_path first!
require $_SERVER['DOCUMENT_ROOT'] . '/min/utils.php';

$jsUri = Minify_groupUri('js');
echo "<script type='text/javascript' src='{$jsUri}'></script>";


GROUPS: SPECIFYING FILES OUTSIDE THE DOC_ROOT

In the groupsConfig.php array, the "//" in the file paths is a shortcut for
the DOCUMENT_ROOT, but you can also specify paths from the root of the filesystem
or relative to the DOC_ROOT:

return array(
'js' => array(
'//js/file.js' // file within DOC_ROOT
,'//../file.js' // file in parent directory of DOC_ROOT
,'C:/Users/Steve/file.js' // file anywhere on filesystem
)
);


QUESTIONS?

http://groups.google.com/group/minify

0 comments on commit 3d94fcb

Please sign in to comment.