From 048c689663f59953551caf421e4728b92f834190 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Thu, 15 May 2008 15:03:46 +0000 Subject: [PATCH] Reorganized examples --- web/examples/1/_groupsSources.php | 11 +++++ web/examples/1/index.php | 62 +++++++++------------------- web/examples/1/m.php | 51 ++++------------------- web/examples/1/test.css | 19 --------- web/examples/2/_groupsSources.php | 2 +- web/examples/2/index.php | 22 +++++++--- web/examples/3/index.php | 37 +++++++++++++++++ web/examples/3/m.php | 43 +++++++++++++++++++ web/examples/{1 => }/jquery-1.2.3.js | 2 +- web/examples/{1 => }/test space.js | 0 web/examples/test.css | 41 ++++++++++++++++++ 11 files changed, 178 insertions(+), 112 deletions(-) create mode 100644 web/examples/1/_groupsSources.php delete mode 100644 web/examples/1/test.css create mode 100644 web/examples/3/index.php create mode 100644 web/examples/3/m.php rename web/examples/{1 => }/jquery-1.2.3.js (99%) rename web/examples/{1 => }/test space.js (100%) create mode 100644 web/examples/test.css diff --git a/web/examples/1/_groupsSources.php b/web/examples/1/_groupsSources.php new file mode 100644 index 0000000..7ab4c94 --- /dev/null +++ b/web/examples/1/_groupsSources.php @@ -0,0 +1,11 @@ + array( + "{$base}/jquery-1.2.3.js" + ,"{$base}/test space.js" + ) + ,'css' => array("{$base}/test.css") +); +unset($base); \ No newline at end of file diff --git a/web/examples/1/index.php b/web/examples/1/index.php index 804d7e5..e3ba2fe 100644 --- a/web/examples/1/index.php +++ b/web/examples/1/index.php @@ -1,19 +1,18 @@ Minify Example 1 - - + + @@ -23,47 +22,26 @@ ob_start(); config.php. Notice that minifying jQuery takes several seconds!.

-

Minify Example 1

+

Minify Example 1 : Groups controller + Far-off Expires header

-

This is an example of Minify serving a directory of single css/js files. -Each file is minified and sent with HTTP encoding (browser-permitting).

+

In this example, we use a single config file _groupsSources.php +to specify files for minification. During HTML generation, +Minify_Build is used +to stamp the latest modification times onto the minify URLs. Our minify server, +m.php, then sends the content with far-off Expires headers.

-

In this example, if m.php detects $_GET['v'], a 30-day Expires header is -sent rather than the conditional GET.

+

If one of our sources is modified, its URL (particularly the query string) is +changed in the HTML document, causing the browser to request a new version.

+

Minify tests

-

Link to this page (F5 can trigger no-cache headers)

+

Test client cache

+

Reload page (F5 can trigger no-cache headers)

- - - + - - $content - ,'id' => __FILE__ - ,'lastModifiedTime' => filemtime(__FILE__) - - // also minify the CSS/JS inside the HTML - ,'minifyAll' => true -)); \ No newline at end of file + \ No newline at end of file diff --git a/web/examples/1/m.php b/web/examples/1/m.php index 1cb7dfe..53e8af0 100644 --- a/web/examples/1/m.php +++ b/web/examples/1/m.php @@ -1,49 +1,14 @@ array(dirname(__FILE__) . '/' . $filename) - ,'setExpires' => $setExpires - )); - exit(); - } +if ($minifyCachePath) { + Minify::useServerCache($minifyCachePath); } -header("HTTP/1.0 404 Not Found"); -echo "HTTP/1.0 404 Not Found"; \ No newline at end of file +Minify::serve('Groups', array( + 'groups' => $groupsSources + ,'setExpires' => time() + 86400 * 365 +)); diff --git a/web/examples/1/test.css b/web/examples/1/test.css deleted file mode 100644 index 0cb8a59..0000000 --- a/web/examples/1/test.css +++ /dev/null @@ -1,19 +0,0 @@ -/* Test file to minify */ - -/* Minify copyright notice here... */ - -h1 { - color: #00cc00; - font-size: 20px; -} - -ul, li { - padding:0; - margin:0; - display:block; - font-family: monospace; -} - -#cssFail span { - display: none; -} \ No newline at end of file diff --git a/web/examples/2/_groupsSources.php b/web/examples/2/_groupsSources.php index dd15b1e..7ab4c94 100644 --- a/web/examples/2/_groupsSources.php +++ b/web/examples/2/_groupsSources.php @@ -1,6 +1,6 @@ array( "{$base}/jquery-1.2.3.js" diff --git a/web/examples/2/index.php b/web/examples/2/index.php index 55cf396..f4f4f3b 100644 --- a/web/examples/2/index.php +++ b/web/examples/2/index.php @@ -15,11 +15,12 @@ ob_start(); Minify Example 2 + @@ -29,26 +30,35 @@ ob_start(); config.php. Notice that minifying jQuery takes several seconds!.

-

Minify Example 2

+

Minify Example 2: Minifying Everything

-

This is an example using Minify_Build and the Groups controller to -automatically create versioned minify URLs

+

In this example, external Javascript and CSS minification is identical to +example 1, but here Minify is also used to minify and serve the HTML, including +the contents of all <style> and <script> +elements.

+

As the document is XHTML, Minify_HTML places the 2nd <script> +element in a CDATA section because it contains "<". The output is valid XHTML.

+ +

Minify tests

-

Link to this page (F5 can trigger no-cache headers)

+

Test client cache

+

Reload page (F5 can trigger no-cache headers)

diff --git a/web/examples/3/index.php b/web/examples/3/index.php new file mode 100644 index 0000000..3c047e2 --- /dev/null +++ b/web/examples/3/index.php @@ -0,0 +1,37 @@ + + + + + Minify Example 3 + + + + + + +

Note: You should always enable caching using +Minify::useServerCache(). For the examples this can be set in +config.php. Notice that minifying jQuery takes several seconds!.

+ + +

Minify Example 3: Files controller

+ +

This is an example of Minify serving a directory of single css/js files. +Each file is minified and sent with HTTP encoding (browser-permitting).

+ +

Minify tests

+ + +

Test client cache

+

Reload page (F5 can trigger no-cache headers)

+ + + + + \ No newline at end of file diff --git a/web/examples/3/m.php b/web/examples/3/m.php new file mode 100644 index 0000000..ebec8b4 --- /dev/null +++ b/web/examples/3/m.php @@ -0,0 +1,43 @@ + array(dirname(__FILE__) . '/../' . $filename) + )); + exit(); + } +} + +header("HTTP/1.0 404 Not Found"); +echo "HTTP/1.0 404 Not Found"; \ No newline at end of file diff --git a/web/examples/1/jquery-1.2.3.js b/web/examples/jquery-1.2.3.js similarity index 99% rename from web/examples/1/jquery-1.2.3.js rename to web/examples/jquery-1.2.3.js index 2e43a82..c5a3337 100644 --- a/web/examples/1/jquery-1.2.3.js +++ b/web/examples/jquery-1.2.3.js @@ -1,5 +1,5 @@ (function(){ -/* +/*! * jQuery 1.2.3 - New Wave Javascript * * Copyright (c) 2008 John Resig (jquery.com) diff --git a/web/examples/1/test space.js b/web/examples/test space.js similarity index 100% rename from web/examples/1/test space.js rename to web/examples/test space.js diff --git a/web/examples/test.css b/web/examples/test.css new file mode 100644 index 0000000..0b0290c --- /dev/null +++ b/web/examples/test.css @@ -0,0 +1,41 @@ +/* Test file to minify */ + +/*! copyright notice here... */ + +html { + margin:0; + padding:0; + background:#aaa; +} +body { + margin:0 auto; + padding:1em; + width:550px; + background:#fff; +} +body > *:first-child {margin-top:0;} + +h1 { + color: #00cc00; + font-size: 20px; +} +h2 { + color: #009900; + font-size: 17px; +} +h1, h2 {margin:1.3em 0 .3em;} + +p { + margin:0 0 1em; +} + +ul, li { + padding:0; + margin:0; + display:block; + font-family: monospace; +} + +#cssFail span { + display: none; +} \ No newline at end of file