diff options
Diffstat (limited to 'admin/survey/minify/docs')
18 files changed, 1138 insertions, 0 deletions
diff --git a/admin/survey/minify/docs/AlternateFileLayouts.wiki.md b/admin/survey/minify/docs/AlternateFileLayouts.wiki.md new file mode 100644 index 0000000..2333cd7 --- /dev/null +++ b/admin/survey/minify/docs/AlternateFileLayouts.wiki.md @@ -0,0 +1,30 @@ +If you test sites in a subdirectory (e.g. `http://localhost/testSite/`) rather than a virtualhost, then you'll need to adjust the way you use Minify to rewrite CSS correctly.
+
+1. Place the following in `config.php`:
+
+```php
+// Set the document root to be the path of the "site root"
+$min_documentRoot = substr(__FILE__, 0, -11);
+
+// Set $sitePrefix to the path of the site from the webserver's real docroot
+list($sitePrefix) = explode('/index.php', $_SERVER['SCRIPT_NAME'], 2);
+
+// Prepend $sitePrefix to the rewritten URIs in CSS files
+$min_symlinks['//' . ltrim($sitePrefix, '/')] = $min_documentRoot;
+```
+
+2. In the HTML, make your Minify URIs document-relative (e.g. `min/f=js/file.js` and `../min/f=js/file.js`), not root-relative.
+
+Now the `min` application should operate correctly from a subdirectory and will serve files relative to your "site" root rather than the document root. E.g.
+
+| **environment** | production | testing |
+|:----------------|:-----------|:--------|
+| **server document root** | `/home/mysite_com/www` | `/var/www` |
+| **`$min_documentRoot` ("site root")** | `/home/mysite_com/www` | `/var/www/testSite` |
+| **`$sitePrefix`** | (empty) | `/testSite` |
+| **Minify URL** | `http://mysite.com/min/f=js/file1.js` | `http://localhost/testSite/min/f=js/file1.js` |
+| **file served** | `/home/mysite_com/www/js/file1.js` | `/var/www/testSite/js/file1.js` |
+
+Caveats:
+ * This configuration may break the Builder application (located at `/min/builder/`) used to create Minify URIs, but you can still create them by hand.
+ * Make sure you don't reset `$min_symlinks` to a different value lower in your config file.
\ No newline at end of file diff --git a/admin/survey/minify/docs/BuilderApp.wiki.md b/admin/survey/minify/docs/BuilderApp.wiki.md new file mode 100644 index 0000000..f4a5b75 --- /dev/null +++ b/admin/survey/minify/docs/BuilderApp.wiki.md @@ -0,0 +1,9 @@ +Minify ships with "Builder", a simple Javascript app for constructing URIs to use with Minify. ([screenshots of the 2.1.0 version](http://www.mrclay.org/index.php/2008/09/19/minify-21-on-mrclayorg/))
+
+It also does some run-time checks of your PHP and Minify configuration to look for problematic settings like [auto-encoding](CommonProblems.wiki.md#output-is-distortedrandom-chars).
+
+After installation, this is found at **`http://example.com/min/builder/`**
+
+You must enable it by editing `config.php` and setting `$min_enableBuilder = true;`
+
+After use, you should disable it by resetting `$min_enableBuilder = false;`
\ No newline at end of file diff --git a/admin/survey/minify/docs/CommonProblems.wiki.md b/admin/survey/minify/docs/CommonProblems.wiki.md new file mode 100644 index 0000000..cb72b69 --- /dev/null +++ b/admin/survey/minify/docs/CommonProblems.wiki.md @@ -0,0 +1,132 @@ +If this page doesn't help, please post a question on our [Google group](http://groups.google.com/group/minify).
+
+## URIs are re-written incorrectly in CSS output
+
+See [UriRewriting](UriRewriting.wiki.md).
+
+## Builder Fails / 400 Errors
+
+This is usually due to an unusual server setup. You can see the cause of 400 responses using FirePHP (See [Debugging](Debugging.wiki.md)).
+
+## Long URL parameters are ignored
+
+Some server setups will refuse to populate very long `$_GET` params. Use [groups](UserGuide.wiki.md#using-groups-for-nicer-urls) to shorten the URLs.
+
+## PHP/Apache crashes
+
+[PCRE (which provides regular expressions) commonly crashes PHP](https://www.google.com/search?q=pcre+php+crash) and this is nearly impossible to solve in PHP code. Things to try:
+
+ * Raise Apache's [ThreadStackSize](http://stackoverflow.com/a/7597506/3779)
+ * In [php.ini](http://php.net/manual/en/pcre.configuration.php) raise `pcre.backtrack_limit` and `pcre.recursion_limit` to 1000000. These will allow processing longer strings, but also require a larger stack size.
+ * Use YUICompressor instead of PHP-based CSS compressors
+
+## Dealing with Javascript errors
+
+Short answer: **use Minify 2.1.4+, use a pre-compressed version of your file, and rename it `*.min.js` or `*-min.js`**. By default Minify won't try to minify these files (but will still gzip them). The [Compressor Rater](http://compressorrater.thruhere.net/) is handy for compressing files individually.
+
+If the error is in your code, enable [debug mode](Debugging.wiki.md) while debugging your code in Firebug or your favorite browser's Javascript debugger. This will insert comments to allow you to keep track of the individual source locations in the combined file.
+
+If you have Java on your web host, you can use the [wrapper for YUI Compressor](../lib/Minify/YUICompressor.php) instead of JSMin. [This thread](http://groups.google.com/group/minify/browse_thread/thread/f12f25f27e1256fe) shows how a user has done this.
+
+## Javascript isn't being minified
+
+If the filename ends with **`-min.js`** or **`.min.js`**, Minify will assume the file is already compressed and just combine it with any other files.
+
+### Scriptaculous
+
+Scriptaculous 1.8.2 (and probably all 1.x) has an [autoloader script](http://github.com/madrobby/scriptaculous/blob/4b49fd8884920d4ee760b0194431f4f433f878df/src/scriptaculous.js#L54) that requires files to be in a particular place on disk. To serve Scriptaculous modules with Minify, just serve `prototype.js` and the individual support files (e.g. `dragdrop.js`, `effects.js`) and the library should work fine. E.g.:
+
+```
+<script src="/min/f=scriptaculous/lib/prototype.js" type="text/javascript"></script>
+<script src="/min/b=scriptaculous/src&f=effects.js,dragdrop.js" type="text/javascript"></script>
+<script type="text/javascript">
+/* DragDrop and Effects modules can be used here. */
+</script>
+```
+
+## Server cache files won't update
+
+If you upload files using [Coda or Transmit](http://groups.google.com/group/coda-users/browse_thread/thread/572d2dc315ec02e7/) or from a Windows PC to a non-Windows server, your new files may end up with the wrong `mtime` (timestamp) on the server, confusing the cache system.
+
+Setting the [$min\_uploaderHoursBehind option](../config.php#L171) in `config.php` can compensate for this.
+
+WinSCP has a [Daylight Saving Time option](http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time) that can prevent this issue.
+
+This can also occur if your files are changed, and the `mtime` is set in the past (e.g. via a `git checkout` operation). If so you'll have to `touch` the changed files or use some other method to make the `mtime` current.
+
+## Can't see changes in browser
+
+Generally changes aren't seen because a) the browser is refusing to send a new request, or b) the server doesn't recognize that your source files have been modified after the server cache was created.
+
+First, place the Minify URL directly in the address bar and refresh.
+
+If a change is not seen, verify that the server cache file is being updated.
+
+## Disable Caching
+
+If you'd like to temporarily disable the cache without using [debug mode](Debugging.wiki.md), place these settings at the end of `config.php`:
+```php
+// disable server caching
+$min_cachePath = null;
+// prevent client caching
+$min_serveOptions['maxAge'] = 0;
+$min_serveOptions['lastModifiedTime'] = $_SERVER['REQUEST_TIME'];
+```
+**Don't do this on a production server!** Minify will have to combine, minify, and gzencode on every request.
+
+## Character Encodings
+
+_Please_ use UTF-8. The string processing may work on encodings like Windows-1251 but will certainly fail on radically different ones like UTF-16.
+
+If you consistently use a different encoding, in `config.php` set `$min_serveOptions['contentTypeCharset']` to this encoding to send it in the Content-Type header.
+
+Otherwise, set it to `false` to remove it altogether. You can still, in CSS, use the [@charset](http://www.w3.org/TR/CSS2/syndata.html#x50) directive to tell the browser the encoding, but (a) it must appear first and (b) shouldn't appear later in the output (and Minify won't enforce this).
+
+Moral? To minimize problems, use UTF-8 and remove any `@charset` directives from your CSS.
+
+## @imports can appear in invalid locations in combined CSS files
+
+If you combine CSS files, @import declarations can appear after CSS rules, invalidating the stylesheet. As of version 2.1.2, if Minify detects this, it will prepend a warning to the output CSS file. To resolve this, you can either move your @import statements within your files, or enable the option 'bubbleCssImports'.
+
+## Debug mode can cause a Javascript error
+
+This issue was resolved in version 2.1.2.
+
+Debug mode adds line numbers in comments. Unfortunately, in versions <= 2.1.1, if the source file had a string or regex containing (what looks like) a C-style comment token, the algorithm was confused and the injected comments caused a syntax error.
+
+## Minification can cause a Javascript error
+
+This issue was resolved in version 2.1.2.
+
+In rare instances the [JSMin](https://github.com/mrclay/jsmin-php/blob/master/src/JSMin/JSMin.php) algorithm in versions <= 2.1.1 could be confused by regexes in certain contexts and throw an exception. The workaround was to simply wrap the expression in parenthesis. E.g.
+```js
+// in 2.1.1 and previous
+return /'/; // JSMin throws error
+return (/'/); // no error
+```
+
+## Output is distorted/random chars
+
+What you're seeing is a mismatch between the content encoding the browser expects and what it receives.
+
+The usual problem is that a global PHP or web server configuration is causing the output of PHP scripts to be automatically gzipped. Since Minify already outputs gzipped content, the browser receives "double encoded" content which it interprets as noise. The Builder app in 2.1.4 sometimes can tell you which component is causing the auto-encoding.
+
+## Can't specify more than 10 files via URL
+
+Use Minify 2.1.4+. Before there was a setting to adjust the maximum allowed.
+
+## Directory Listing Denied
+
+This may also appear as "Virtual Directory does not allow contents to be listed". Minify requires that the URI `/min/` (a request for a directory listing) result in the execution of `/min/index.php`. On Apache, you would make sure `index.php` is listed in the [DirectoryIndex directive](http://httpd.apache.org/docs/2.0/mod/mod_dir.html#directoryindex). IIS calls this the [Default Document](http://www.iis.net/ConfigReference/system.webServer/defaultDocument).
+
+## "WARN: environment : Local HTTP request failed. Testing cannot continue."
+
+The `test_environment.php` unit test makes a few local HTTP requests to sniff for `zlib.output_compression` and other auto-encoding behavior, which may break Minify's output. This warning will appear if `allow_url_fopen` is disabled in php.ini, but **does not** necessarily mean there is a problem.
+
+If Minify seems to work fine, ignore the warning. If Minify produces garbled output, enable `allow_url_fopen` in php.ini and re-run the tests. The tests may be able to tell you if PHP or your server is automatically encoding output.
+
+Unless you need it in other scripts, disable `allow_url_fopen` once the issue is resolved. Minify does not need it.
+
+## See Also
+
+ * [Debugging](Debugging.wiki.md)
diff --git a/admin/survey/minify/docs/ComponentClasses.wiki.md b/admin/survey/minify/docs/ComponentClasses.wiki.md new file mode 100644 index 0000000..824590f --- /dev/null +++ b/admin/survey/minify/docs/ComponentClasses.wiki.md @@ -0,0 +1,16 @@ +# PHP5 Component Classes
+
+(This information is not updated for version 3)
+
+| **Class** | **Functionality** |
+|:----------|:------------------|
+| [Minify](http://code.google.com/p/minify/source/browse/min/lib/Minify.php) | Combine, process, and serve pieces of content (usually CSS/JS files). Almost all behavior is configurable including request handling (via [controllers](http://code.google.com/p/minify/source/browse/min/lib/Minify/Controller/)), HTTP headers & encoding, caching ([file/APC/memcached](http://code.google.com/p/minify/source/browse/min/lib/Minify/Cache/)), and compression functions (by default, the classes below) |
+| [JSMin](http://code.google.com/p/minify/source/browse/min/lib/JSMin.php) | A port of [jsmin.c](http://www.crockford.com/javascript/jsmin.html), extended to preserve some multi-line comments and IE conditional comments (since these occasionally have their [uses](http://dean.edwards.name/weblog/2007/03/sniff/)). |
+| [Minify\_CSS](http://code.google.com/p/minify/source/browse/min/lib/Minify/CSS.php) | Uses the two classes below to minify CSS and optionally rewrite URIs. |
+| [Minify\_CSS\_Compressor](http://code.google.com/p/minify/source/browse/min/lib/Minify/CSS/Compressor.php) | Agressively minifies CSS. Includes a thorough [test suite](http://code.google.com/p/minify/source/browse/min_unit_tests/_test_files/css/) to make sure most common [hacks](http://code.google.com/p/minify/source/browse/min_unit_tests/_test_files/css/hacks.css) and [unusual syntaxes](http://code.google.com/p/minify/source/browse/min_unit_tests/_test_files/css/unusual_strings.css) are preserved. |
+| [Minify\_CSS\_UriRewriter](http://code.google.com/p/minify/source/browse/min/lib/Minify/CSS/UriRewriter.php) | In CSS files, rewrites file-relative URIs as root-relative. With [test suite](http://code.google.com/p/minify/source/browse/min_unit_tests/_test_files/css_uriRewriter/) |
+| [Minify\_HTML](http://code.google.com/p/minify/source/browse/min/lib/Minify/HTML.php) | Agressively minifies (X)HTML markup. Preserves TEXTAREA/PRE contents, can invoke minifiers on STYLE and SCRIPT blocks, and wraps content in CDATA blocks in XHTML when necessary. Includes [test suite](http://code.google.com/p/minify/source/browse/min_unit_tests/_test_files/html/). |
+| [Minify\_YUICompressor](http://code.google.com/p/minify/source/browse/min/lib/Minify/YUICompressor.php) | (Experimental) PHP wrapper for invoking the Java-based [YUI Compressor](http://developer.yahoo.com/yui/compressor/) |
+| [Minify\_ImportProcessor](http://code.google.com/p/minify/source/browse/min/lib/Minify/ImportProcessor.php) | Linearize a CSS/JS file by including content specified by CSS import declarations. In CSS files, relative URIs are fixed. This has a test suite but should be considered "experimental". |
+| [HTTP\_Encoder](http://code.google.com/p/minify/source/browse/min/lib/HTTP/Encoder.php) | Applies HTTP encoding to content. Can serve content with conditional encoding based on Accept-Encoding headers (parsed according to [HTTP spec](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)) and known browser bugs. |
+| [HTTP\_ConditionalGet](http://code.google.com/p/minify/source/browse/min/lib/HTTP/ConditionalGet.php) | Implements HTTP conditional GETs via a simple, flexible API. |
\ No newline at end of file diff --git a/admin/survey/minify/docs/CookBook.wiki.md b/admin/survey/minify/docs/CookBook.wiki.md new file mode 100644 index 0000000..85828da --- /dev/null +++ b/admin/survey/minify/docs/CookBook.wiki.md @@ -0,0 +1,142 @@ +Unless mentioned, all the following snippets go in `config.php`.
+
+## Faster Cache Performance
+
+By default, Minify uses `Minify_Cache_File`. It uses `readfile`/`fpassthru` to improve performance over most file-based systems, but it's still file IO, so the following caching options should be faster. In all cases, Minify cache ids begin with `"minify_"`.
+
+### APC
+
+```php
+$min_cachePath = new Minify_Cache_APC();
+```
+
+### Memcache
+
+You must create and connect your Memcache object then pass it to `Minify_Cache_Memcache`'s constructor.
+```php
+$memcache = new Memcache;
+$memcache->connect('localhost', 11211);
+$min_cachePath = new Minify_Cache_Memcache($memcache);
+```
+
+### Zend Platform
+
+```php
+$min_cachePath = new Minify_Cache_ZendPlatform();
+```
+
+### XCache
+
+```php
+$min_cachePath = new Minify_Cache_XCache();
+```
+
+### WinCache
+
+```php
+$min_cachePath = new Minify_Cache_WinCache();
+```
+
+## Closure Compiler API Wrapper
+
+An [experimental wrapper for Google's closure compiler API](../lib/Minify/JS/ClosureCompiler.php) is available for compressing Javascript. If the API fails for any reason, JSMin is used as the default backup minifier.
+```php
+$min_serveOptions['minifiers'][Minify::TYPE_JS] = array('Minify_JS_ClosureCompiler', 'minify');
+```
+
+## YUICompressor
+
+If your host can execute Java, you can use Minify's YUI Compressor wrapper. You'll need the latest [yuicompressor-x.x.x.jar](https://github.com/yui/yuicompressor/releases) and a temp directory. Place the .jar in `min/lib`, then:
+```php
+function yuiJs($js) {
+ Minify_YUICompressor::$jarFile = __DIR__ . '/lib/yuicompressor-x.x.x.jar';
+ Minify_YUICompressor::$tempDir = '/tmp';
+ return Minify_YUICompressor::minifyJs($js);
+}
+$min_serveOptions['minifiers'][Minify::TYPE_JS] = 'yuiJs';
+```
+
+To use YUIC for CSS with fixed URIs:
+
+```php
+function yuiCss($css, $options) {
+ Minify_YUICompressor::$jarFile = __DIR__ . '/lib/yuicompressor-x.x.x.jar';
+ Minify_YUICompressor::$tempDir = '/tmp';
+ $css = Minify_YUICompressor::minifyCss($css);
+
+ $css = Minify_CSS_UriRewriter::rewrite(
+ $css
+ ,$options['currentDir']
+ ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
+ ,isset($options['symlinks']) ? $options['symlinks'] : array()
+ );
+ return $css;
+}
+$min_serveOptions['minifiers'][Minify::TYPE_CSS] = 'yuiCss';
+```
+
+## Legacy CSS compressor
+
+In 3.x, Minify uses [CSSmin](https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port), a PHP port of the YUI CSS compressor. To use the compressor that came with Minify 2.x (not recommended), uncomment this line in your `config.php` file:
+
+```php
+//$min_serveOptions['minifiers'][Minify::TYPE_CSS] = array('Minify_CSS', 'minify');
+```
+
+## Server-specific Options
+
+You may need to have different options depending on what server you're on. You can do this just how you'd expect:
+```php
+if ($_SERVER['SERVER_NAME'] == 'myTestingWorkstation') {
+ // testing
+ $min_allowDebugFlag = true;
+ $min_errorLogger = true;
+ $min_enableBuilder = true;
+ $min_cachePath = 'c:\\WINDOWS\\Temp';
+ $min_serveOptions['maxAge'] = 0; // see changes immediately
+} else {
+ // production
+ $min_allowDebugFlag = false;
+ $min_errorLogger = false;
+ $min_enableBuilder = false;
+ $min_cachePath = '/tmp';
+ $min_serveOptions['maxAge'] = 86400;
+}
+```
+
+## Site in a Subdirectory
+
+If you test/develop sites in a subdirectory (e.g. `http://localhost/siteA/`), see AlternateFileLayouts.
+
+## Group-specific Options
+
+In "group" requests, `$_GET['g']` holds the group key, so you can code based on it:
+```php
+if (isset($_GET['g'])) {
+ switch ($_GET['g']) {
+ case 'js' : $min_serveOptions['maxAge'] = 86400 * 7;
+ break;
+ case 'css': $min_serveOptions['contentTypeCharset'] = 'iso-8859-1';
+ break;
+ }
+}
+```
+
+## File/Source-specific Options
+
+See CustomSource.
+
+## Processing Output After Minification
+
+If `$min_serveOptions['postprocessor']` is set to a callback, Minify will pass the minified content to this function with type as the second argument. This allows you to apply changes to your minified content without making your own custom minifier. E.g.:
+```php
+function postProcess($content, $type) {
+ if ($type === Minify::TYPE_CSS) {
+ require_once 'CssColorReplacer.php';
+ return CssColorReplacer::process($content);
+ }
+ return $content;
+}
+$min_serveOptions['postprocessor'] = 'postProcess';
+```
+This function is only called once immediately after minification and its output is stored in the cache.
\ No newline at end of file diff --git a/admin/survey/minify/docs/CustomServer.wiki.md b/admin/survey/minify/docs/CustomServer.wiki.md new file mode 100644 index 0000000..7d7b266 --- /dev/null +++ b/admin/survey/minify/docs/CustomServer.wiki.md @@ -0,0 +1,108 @@ +Please see the UserGuide if you're just getting started with Minify. This guide is for more advanced users who wish to implement an HTTP server in PHP using the `Minify` class.
+
+## Pull in Minify via Composer
+
+In composer.json:
+```
+ "require": {
+ "mrclay/minify": "~3"
+ },
+```
+
+```bash
+composer install
+```
+
+## Set up autoloading, caching, and the Minify instance
+
+Minify ships with several [cache classes](https://github.com/mrclay/minify/tree/master/lib/Minify/Cache) for files, APC, memcache, etc.:
+
+```php
+require __DIR__ . '/vendor/autoload.php';
+
+$cache = new Minify_Cache_APC();
+$minify = new Minify($cache);
+```
+
+## Create the environment and the factory for source objects
+
+```php
+$env = new Minify_Env();
+$sourceFactory = new Minify_Source_Factory($env, [], $cache);
+```
+
+## Choose a Minify controller
+
+Minify uses controller classes to analyze the environment (HTTP requests) and determine which sources will make up the response. (The content isn't always returned; if the browser's cache is valid, Minify can return a 304 header instead).
+
+The `Files` controller doesn't care about the HTTP request. It just specifies a given array of sources (file paths or [source objects](CustomSource.md)).
+
+The `Groups` controller uses `$_SERVER['PATH_INFO']` to choose from an array of source lists. There's an example at the end of this page.
+
+The Files controller is simple, so we'll use it here.
+
+```php
+$controller = new Minify_Controller_Files($env, $sourceFactory);
+```
+
+## Set up service and controller options
+
+A single array is used for configuring both the behavior of `Minify::serve` (see the [default options](../lib/Minify.php#L73)) and the controller, which has its own option keys.
+
+The Files controller only needs one key: `files`: the array of sources to be combined and served.
+
+The only `serve` option we'll set is `maxAge` (the default is only 1800 seconds).
+
+```php
+$options = [
+ // options for the controller
+ 'files' => ['//js/file1.js', '//js/file2.js'],
+
+ // options for Minify::serve
+ 'maxAge' => 86400,
+ 'minifierOptions' => [
+ 'text/css' => [
+ 'docRoot' => $env->getDocRoot(), // allows URL rewriting
+ ],
+ ],
+];
+```
+
+Note: `files` can also accept `Minify_Source` objects, which allow serving more than static files.
+
+## Handle the request
+
+```php
+$minify->serve($controller, $options);
+```
+
+That's it...
+
+Minify's default application (`index.php`) is implemented similarly, but uses the `MinApp` controller. If you need URL rewriting in CSS files, you'll need to configure
+
+# The Request Cycle
+
+In handling a request, `Minify::serve` does a number of operations:
+
+ 1. Minify merges your given options with its default options
+ 1. calls the controller's `createConfiguration()`, which analyzes the request and returns a `Minify_ServeConfiguration` object, encapsulating the source objects found.
+ 1. uses `analyzeSources()` to determine the Content-Type and last modified time.
+ 1. determines if the browser accepts gzip
+ 1. validates the browser cache (optionally responding with a 304)
+ 1. validates the server cache. If it needs refreshing, `combineMinify()` fetchs and combines the content of each source.
+ 1. sets up headers to be sent
+ 1. either returns the headers and content in an array (if `quiet` is set), or sends it to the browser.
+
+# Using the Groups controller
+
+The Groups controller uses `$_SERVER['PATH_INFO']` to select an array of sources from the given options:
+```
+$options = [
+ 'groups' => [
+ 'js' => ['//js/file1.js', '//js/file2.js'],
+ 'css' => ['//css/file1.css', '//css/file2.css'],
+ ],
+];
+```
+
+With the above, if you request `http://example.org/myServer.php/css`, Apache will set `$_SERVER['PATH_INFO'] = '/css'` and the sources in `$options['groups']['css']` will be served.
diff --git a/admin/survey/minify/docs/CustomSource.wiki.md b/admin/survey/minify/docs/CustomSource.wiki.md new file mode 100644 index 0000000..41764f6 --- /dev/null +++ b/admin/survey/minify/docs/CustomSource.wiki.md @@ -0,0 +1,136 @@ +In `groupsConfig.php`, usually you specify source file paths using strings like `/path/to/file.js` or `//js/file1.js` (Minify expands this to `"{$_SERVER['DOCUMENT_ROOT']}/js/file1.js"` ).
+
+Instead of a string, you may substitute an instance of class `Minify_Source`. This allows you to customize how minification is applied, and/or pull content from a non-file location (e.g. a URL).
+
+### Example: filepath
+
+In the `$spec` array, set the key `filepath` to produce a source based on a file path:
+
+```php
+$src1 = new Minify_Source(array(
+ 'filepath' => '//js/file1.js',
+));
+$src2 = new Minify_Source(array(
+ 'filepath' => '//js/file2.js',
+));
+
+return [
+ 'js' => [$src1, $src2]
+];
+```
+
+Note the above is functionally identical to:
+```php
+return [
+ 'js' => ['//js/file1.js', '//js/file2.js'],
+];
+```
+
+### Example: Specify a different minifier or none at all
+
+To change minifier, set `minifier` to a [callback](http://php.net/manual/en/language.pseudo-types.php)`*` or the empty string (for none):
+
+**`*`Prepare for `groupsConfig.php` to be executed more than once.** (This is likely if you're using the functions in `/min/utils.php`.) In practice this just means making sure functions are conditionally defined if they don't already exist, etc.
+
+```php
+$src1 = new Minify_Source(array(
+ 'filepath' => '//js/file1.js',
+ 'minifier' => 'myJsMinifier',
+));
+$src2 = new Minify_Source(array(
+ 'filepath' => '//js/file2.js',
+ 'minifier' => 'Minify::nullMinifier', // don't compress
+));
+```
+In the above, `JmyJsMinifier()` is only called when the contents of `$src1` is needed.
+
+**`*`Do _not_ use `create_function()` or anonymous functions for the minifier.** The internal names of these function tend to vary, causing endless cache misses, killing performance and filling cache storage up.
+
+## Non-File Sources
+
+You're not limited to flat js/css files, but without `filepath`, the `$spec` array must contain these keys:
+
+ * **`id `** a unique string id for this source. (e.g. `'my source'`)
+ * **`getContentFunc `** a [callback](http://php.net/manual/en/language.pseudo-types.php) that returns the content. The function is only called when the cache is rebuilt.
+ * **`contentType `** `Minify::TYPE_JS` or `Minify::TYPE_CSS`
+ * **`lastModified `** a timestamp indicating when the content last changed. (If you can't determine this quickly, you can "fake" it using a step function, causing the cache to be periodically rebuilt.)
+
+### Example: Content from a URL
+
+Here we want to fetch javascript from a URL. We don't know when it will change, so we use a stepping expression to re-fetch it every midnight:
+```php
+if (! function_exists('src1_fetch')) {
+ function src1_fetch() {
+ return file_get_contents('http://example.org/javascript.php');
+ }
+}
+$src1 = new Minify_Source([
+ 'id' => 'source1',
+ 'getContentFunc' => 'src1_fetch',
+ 'contentType' => Minify::TYPE_JS,
+ 'lastModified' => ($_SERVER['REQUEST_TIME'] - $_SERVER['REQUEST_TIME'] % 86400),
+]);
+```
+
+If you know that the URL content only depends on a few local files, you can use the maximum of their `mtime`s as the `lastModified` key:
+```php
+$src1 = new Minify_Source([
+ 'id' => 'source1',
+ 'getContentFunc' => 'src1_fetch',
+ 'contentType' => Minify::TYPE_JS,
+ 'lastModified' => max(
+ filemtime('/path/to/javascript.php')
+ ,filemtime('/path/to/javascript_input.css')
+ ),
+]);
+```
+
+## Performance Considerations
+
+Be aware that all the code you put in `groupsConfig.php` will be evaluated upon every request like `/min/g=...`, so make it as light as possible.
+
+If you wish to keep `groupsConfig.php` "clean", you can alternately create a separate PHP script that manually sets up sources, caching, options, and calls Minify::serve().
+
+```php
+// myServer.php
+/**
+ * This script implements a Minify server for a single set of sources.
+ * If you don't want '.php' in the URL, use mod_rewrite...
+ */
+
+require __DIR__ . '/vendor/autoload.php';
+
+// setup Minify
+$cache = new Minify_Cache_File();
+$minify = new Minify($cache);
+$env = new Minify_Env();
+$sourceFactory = new Minify_Source_Factory($env, [], $cache);
+$controller = new Minify_Controller_Files($env, $sourceFactory);
+
+function src1_fetch() {
+ return file_get_contents('http://example.org/javascript.php');
+}
+
+// setup sources
+$sources = [];
+$sources[] = new Minify_Source([
+ 'id' => 'source1',
+ 'getContentFunc' => 'src1_fetch',
+ 'contentType' => Minify::TYPE_JS,
+ 'lastModified' => max(
+ filemtime('/path/to/javascript.php'),
+ filemtime('/path/to/javascript_input.js')
+ ),
+]);
+$sources[] = '//file2.js';
+$sources[] = '//file3.js';
+
+// setup serve and controller options
+$options = [
+ 'files' => $sources,
+ 'maxAge' => 86400,
+];
+
+// handle request
+$minify->serve($controller, $options);
+```
diff --git a/admin/survey/minify/docs/Debugging.wiki.md b/admin/survey/minify/docs/Debugging.wiki.md new file mode 100644 index 0000000..dfbb475 --- /dev/null +++ b/admin/survey/minify/docs/Debugging.wiki.md @@ -0,0 +1,80 @@ +# Server Errors
+
+| **Code** | **Most likely cause** |
+|:---------|:----------------------|
+| 400 | Controller failed to return valid set of sources to serve |
+| 500 | Minifier threw exception (e.g. JSMin choked on syntax) |
+
+You can find details by enabling FirePHP logging:
+
+ 1. Install/enable FirePHP for [Firefox](https://addons.mozilla.org/en-US/firefox/addon/6149) or [Chrome](https://chrome.google.com/webstore/detail/firephp4chrome/gpgbmonepdpnacijbbdijfbecmgoojma?hl=en-US).
+ 1. Open the Chrome DevTools/Firebug console
+ 1. Set `$min_errorLogger = true;` in config.php
+ 1. Reload the Minify URL
+
+Hopefully you'll see the error appear:
+
+```
+Minify: Something bad happened!
+```
+
+# Javascript/CSS Problems
+
+When Javascript errors occur, or URIs in CSS files are incorrectly rewritten, enable "debug mode" to ease debugging combined files:
+
+ 1. Set `$min_allowDebugFlag = true;` in config.php
+ 1. Append `&debug` to the Minify URI. E.g. `/min/?f=script1.js,script2.js&debug` (or use the bookmarklet provided by /min/builder/)
+
+In "debug mode":
+
+ * comments are inserted into the output showing you line numbers in the original file(s)
+ * no minification is performed
+ * In CSS, URI rewriting _is_ performed
+ * In CSS, a leading comment shows how URIs were rewritten.
+
+Example: a combination of two Javascript files in debug mode
+
+```js
+/* firstFile.js */
+
+/* 1 */ (function () {
+/* 2 */ if (window.foo) {
+...
+/* 11 */ })();
+
+;
+/* secondFile.js */
+
+/* 1 */ var Foo = window.Foo || {};
+/* 2 */
+...
+```
+
+Example: Top of CSS output in debug mode
+
+```
+docRoot : M:\home\foo\www
+currentDir : M:\home\foo\www\css
+
+file-relative URI : typography.css
+path prepended : M:\home\foo\www\css\typography.css
+docroot stripped : \css\typography.css
+traversals removed : /css/typography.css
+
+file-relative URI : ../images/bg.jpg
+path prepended : M:\home\foo\www\css\..\images\bg.jpg
+docroot stripped : \css\..\images\bg.jpg
+traversals removed : /images/bg.jpg
+```
+
+### Tips for handling Javascript errors
+
+ * Use the latest version (2.1.4 beta as of Dec 2010)
+ * Try [debug mode](#javascriptcss-problems) to make the combined file more readable (and error locations findable)
+ * Find out if other browsers have the same error
+ * For pre-minified files, make the filenames end in `.min.js` or `-min.js`, which will prevent Minify from altering them
+ * Test your scripts in [JSLint](http://www.jslint.com/).
+
+## See Also
+
+ * [CommonProblems](CommonProblems.wiki.md)
diff --git a/admin/survey/minify/docs/FAQ.wiki.md b/admin/survey/minify/docs/FAQ.wiki.md new file mode 100644 index 0000000..738a5b5 --- /dev/null +++ b/admin/survey/minify/docs/FAQ.wiki.md @@ -0,0 +1,51 @@ +## Minify (JSMin) doesn't compress as much as product XYZ. Why not?
+
+The simple JSMin algorithm is the most reliable in PHP, but check the [CookBook](CookBook.wiki.md) to plug in other minifiers.
+
+## How fast is it?
+
+If you [serve static files](../static/README.md), it's as fast as your web server, and you should do this for high-traffic sites.
+
+The PHP-based server is not as fast, but still performs well thanks to an internal cache. Tips:
+
+ * **Use a reverse proxy** to cache the Minify URLs. This is by far the most important tip.
+ * Revision your Minify URIs (so far-off Expires headers will be sent). One way to do this is using [groups](UserGuide.wiki.md#using-groups-for-nicer-urls) and the [Minify_groupUri()](UserGuide.wiki.md#far-future-expires-headers) utility function. Without this, clients will re-request Minify URLs every 30 minutes to check for updates.
+ * Use the [APC/Memcache adapters](CookBook.wiki.md).
+
+## Does it support gzip compression?
+
+Yes. Based on the browser's Accept-Encoding header.
+
+## Does it work with PHP opcode caches?
+
+Yes, and you can also use [APC for content caching](CookBook.wiki.md).
+
+## Can it minify remote files/the output of dynamic scripts?
+
+[Yes](CustomSource.wiki.md#non-file-sources), but it's not a straightforward setup, and probably best avoided.
+
+## Is there a minifier for HTML?
+
+The class `Minify_HTML` can do this (and minify embedded STYLE and SCRIPT elements), but it's too slow to use directly. You'd want to integrate it into a system that caches the output. E.g., in a CMS, keep one copy for editing and one minified for serving.
+
+## How does it ensure that the client can't request files it shouldn't have access to?
+
+Minify allows files to be specified using the URI, or using pre-configured sets of files. With URI-specified files, Minify is very careful to serve only JS/CSS files that are already public on your server, but if you hide public directories--with .htaccess, e.g.--Minify can't know that. Obvious Tip: don't put sensitive info in JS/CSS files inside DOC_ROOT :)
+
+An included option can disable URI-specified files so Minify will serve only the pre-configured file sets.
+
+## Is it used in production by any large-scale websites?
+
+The libraries are used in many CMS's and frameworks, but the use of `index.php` to serve URLs like http://example.com/min/f=hello.js probably is rare. Minify is made to drop in place to boost small to medium sites not already built for performance.
+
+Version 2.1.1 had 54K downloads.
+
+## Can I use it with my commercial website or product?
+
+Yes. Minify is distributed under the [New BSD License](http://www.opensource.org/licenses/bsd-license.php).
+
+## How can I tell if my server cache is working?
+
+The easiest way is to place a Minify URL directly in your browser's address bar and refresh (F5), which should override the client-side caching that Minify specifies and force Minify to send you a complete response. With cache working, this response should take 100ms or so. Without cache, it could be multiple seconds.
+
+If you have file access to the server you can check your cache path directly for filenames beginning with `minify_`.
\ No newline at end of file diff --git a/admin/survey/minify/docs/Install.wiki.md b/admin/survey/minify/docs/Install.wiki.md new file mode 100644 index 0000000..328e873 --- /dev/null +++ b/admin/survey/minify/docs/Install.wiki.md @@ -0,0 +1,61 @@ +# Installation
+
+Minify requires PHP 5.3+, `git`, and `composer`.
+
+## Typical Installation
+
+Clone the project into the `min/` directory inside your document root and install its dependencies:
+
+```bash
+cd /path/to/public_html
+git clone https://github.com/mrclay/minify.git min
+cd min
+composer install --no-dev
+```
+
+**Note:** If you do this on localhost, make sure the `min/vendor/` directory gets deployed to production.
+
+## Installing as a composer dependency
+
+Add `"mrclay/minify": "~3.0.0"` to your site's composer.json, and `composer install`.
+
+The following assumes your `vendor` directory is in your document root. Adjust the `MINIFY` path as needed:
+
+```bash
+cd /path/to/public_html
+mkdir min
+MIN=min/
+MINIFY=vendor/mrclay/minify/
+cp ${MINIFY}example.index.php ${MIN}index.php
+cp ${MINIFY}.htaccess ${MIN}
+cp ${MINIFY}config.php ${MIN}
+cp ${MINIFY}groupsConfig.php ${MIN}
+cp ${MINIFY}quick-test.js ${MIN}
+cp ${MINIFY}quick-test.css ${MIN}
+```
+
+Edit `min/index.php` to remove the ``die()`` statement and adjust the `vendor` path as needed.
+
+**Note:** This does not install the [URL builder](BuilderApp.wiki.md), but it's not necessary for operation.
+
+## Verifing it works
+
+You can verify it works via these two URLs:
+
+* http://example.org/min/?f=min/quick-test.js
+* http://example.org/min/?f=min/quick-test.css
+
+If your server supports mod_rewrite, the `?` are not necessary:
+
+* http://example.org/min/f=min/quick-test.js
+* http://example.org/min/f=min/quick-test.css
+
+## Having trouble?
+
+Write the [Google Group](http://groups.google.com/group/minify) for help.
+
+## More links
+
+* [Usage instructions](UserGuide.wiki.md)
+* [Cookbook](CookBook.wiki.md) for more advanced options
+* [All docs](docs)
diff --git a/admin/survey/minify/docs/MinApp.wiki.md b/admin/survey/minify/docs/MinApp.wiki.md new file mode 100644 index 0000000..07bb017 --- /dev/null +++ b/admin/survey/minify/docs/MinApp.wiki.md @@ -0,0 +1,14 @@ +"Min" is the front end application `index.php` that handles requests to `http://example.com/min/` and responds with compressed/combined content.
+
+When the documentation refers to "Minify" it usually means this application, but sometimes refers to the [ComponentClasses](ComponentClasses.wiki.md).
+
+User-configurable files:
+
+ * `/config.php`: general configuration
+ * `/groupsConfig.php`: configuration of pre-defined groups of files
+
+Other files of interest:
+
+ * `/.htaccess`: rewrites URLs for the front controller
+ * `/index.php`: front controller
+ * `/lib/Minify/Controller/MinApp.php`: determines which files are combined based on `$_GET`, sets some default options
diff --git a/admin/survey/minify/docs/UriRewriting.wiki.md b/admin/survey/minify/docs/UriRewriting.wiki.md new file mode 100644 index 0000000..f6c9b19 --- /dev/null +++ b/admin/survey/minify/docs/UriRewriting.wiki.md @@ -0,0 +1,73 @@ +## Default operation
+
+Minify uses an algorithm to rewrite relative URIs in CSS output to root-relative URIs so that each link points to the same location it did in its original file.
+
+Say your style sheet `http://example.org/theme/fashion/style.css` contains:
+```
+body { background: url(bg.jpg); }
+```
+
+When Minify serves this content (from `http://example.org/min/f=theme/fashion/style.css` or `http://example.org/min/g=css`) it re-writes the URI so the image is correctly linked:
+```
+body{background:url(/theme/fashion/bg.jpg)}
+```
+
+You can see the steps used to rewrite your URIs by enabling [debug mode](Debugging.wiki.md).
+
+## Disable Rewriting
+
+You can disable the automatic rewriting by setting this in config.php:
+```php
+$min_serveOptions['rewriteCssUris'] = false;
+```
+
+## Manual Rewriting
+
+You can manually rewrite relative URIs in CSS in a couple ways. The simplest is to prepend a string to each relative URI:
+```php
+$min_serveOptions['rewriteCssUris'] = false;
+$min_serveOptions['minifierOptions'][Minify::TYPE_CSS]['prependRelativePath'] = '/css/';
+```
+
+Or you can run the minified output through a custom [post-processor](CookBook.wiki.md#Processing_Output_After_Minification.md) function.
+
+## Document Root Confusion
+
+Out-of-the-box, Minify gets confused when `min` is placed in a subdirectory of the real document root. There's now a [simple workaround](AlternateFileLayouts.md) for this, making `min` more portable.
+
+## Aliases / Symlinks / Virtual Directories
+
+Whether you use [aliases](http://httpd.apache.org/docs/2.2/mod/mod_alias.html), [symlinks](http://en.wikipedia.org/wiki/Symbolic_link), or [virtual directories](http://msdn.microsoft.com/en-us/library/zwk103ab.aspx), if you make content outside of the DOC\_ROOT available at public URLs, Minify may need manual configuration of the `$min_symlinks` option to rewrite some URIs correctly. Consider this scenario, where `http://example.org/static/style.css` will serve `/etc/static_content/style.css`:
+
+| document root | `/var/www` |
+|:------------------|:--------------------------------------------|
+| Apache mod\_alias | `Alias /static /etc/static_content` |
+| ...or symlink | `ln -s /etc/static_content /var/www/static` |
+
+In `/config.php` you'll need the following:
+```php
+// map URL path to file path
+$min_symlinks = array(
+ '//static' => '/etc/static_content'
+);
+```
+This lets Minify know during the rewriting process that an internal file path starting with `/etc/static_content` should be rewritten as a public URI beginning with `/static`.
+
+If your alias target directory is outside of DOC\_ROOT, you'll also need to explicitly allow Minify to serve files from it:
+```php
+$min_serveOptions['minApp']['allowDirs'] = array(
+ '//', // allow from the normal DOC_ROOT
+ '/etc/static_content' // allow from our alias target
+);
+```
+
+### What's my document root?
+
+You can enable the script `min/server-info.php` and open http://example.org/min/server-info.php to find useful `$_SERVER` values. People in the [Google Group](https://groups.google.com/forum/#!forum/minify) might need these to help you.
+
+## It's still not working
+
+ 1. Make sure you have the latest version.
+ 1. Enable [debug mode](Debugging.wiki.md), which will show you the URI transformation process.
+ 1. Check that `$_SERVER['DOCUMENT_ROOT']` is the correct directory path. If not, URI rewriting will fail. If you cannot fix this in httpd.conf, etc., set `$min_documentRoot` in config.php.
+ 1. Paste your [debug mode](Debugging.wiki.md) comment block into a new post on the [minify mailing list](http://groups.google.com/group/minify).
diff --git a/admin/survey/minify/docs/UserGuide.wiki.md b/admin/survey/minify/docs/UserGuide.wiki.md new file mode 100644 index 0000000..1a83c00 --- /dev/null +++ b/admin/survey/minify/docs/UserGuide.wiki.md @@ -0,0 +1,129 @@ +If this page doesn't help, please post a question on our [Google group](http://groups.google.com/group/minify).
+
+# Creating Minify URLs
+
+Let's say you want to serve the file http://example.com/css/foo/bar.css
+
+You would use the URL http://example.com/min/?f=css/foo/bar.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.
+
+To combine multiple files, separate the paths given to "f" with commas.
+
+Let's say you have JS files at these URLs:
+
+* http://example.com/scripts/library-1.5.js
+* http://example.com/scripts/site.js
+
+You'd use the URL http://example.com/min/?f=scripts/library-1.5.js,scripts/site.js
+
+## Shortening URLs with common directories
+
+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=path/to/scripts/library-1.5.js,path/to/scripts/foo/site.js
+* http://example.com/min/?b=path/to/scripts&f=library-1.5.js,site.js,home.js
+
+# Limiting access to 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:
+
+```php
+$min_serveOptions['minApp']['allowDirs'] = ['//js', '//themes/default'];
+```
+
+# Using groups for nicer URLs
+
+For nicer URLs, 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:
+
+```php
+return [
+ 'js' => ['//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 http://example.com/min/?g=js
+
+## Specifying files outside the document 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:
+
+```php
+return [
+ 'js' => [
+ '//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
+ ],
+];
+```
+
+## Multiple groups and files in one URL
+
+E.g.: http://example.com/min/?g=js&f=more/scripts.js
+
+Separate group keys with commas: http://example.com/min/?g=baseCss,css1&f=moreStyles.css
+
+## Creating URLs with the Builder
+
+Enable the [BuilderApp](BuilderApp.wiki.md) via config.php. The default password is "admin", but even if no password is used there's very little server information disclosed.
+
+Browse to http://example.com/min/builder/
+
+The Minify URI Builder will help you create URIs you can use to minify existing files on your site. You can see screenshots and get a feel for this process from this [walkthrough on mrclay.org](http://mrclay.org/index.php/2008/09/19/minify-21-on-mrclayorg/)
+
+You may want to disable the [BuilderApp](BuilderApp.wiki.md) when not in use.
+
+# Far-future Expires headers
+
+Minify can send far-future (one year) Expires headers. To enable this you must add a number or the parameter "v" to the querystring (e.g. `/min/?g=js&1234` or `/min/?g=js&v=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.
+
+You can alternately use the utility function `Minify_getUri()` to get a "versioned" Minify URI for use in your HTML (it sniffs the `mtime` of the files). E.g.:
+
+```php
+require 'path/to/min/utils.php';
+
+$jsUri = Minify_getUri('js'); // a key in groupsConfig.php
+echo "<script src='{$jsUri}'></script>";
+
+$cssUri = Minify_getUri([ // a list of files
+ '//css/styles1.css',
+ '//css/styles2.css',
+]);
+echo "<link rel=stylesheet href='{$cssUri}'>";
+```
+
+# Debug mode
+
+In debug mode, instead of compressing files, Minify sends combined files with comments prepended to each line to show the line number in the original source file. To enable this, set `$min_allowDebugFlag` to `true` in config.php and append `&debug=1` to your URIs. E.g. `/min/?f=script1.js,script2.js&debug=1`
+
+Known issue: files with comment-like strings/regexps can cause problems in this mode.
+
+# Configuration
+
+See [config.php](../config.php) for general config options.
+
+[groupsConfig.php](../groupsConfig.php) holds preset groups of files to minify. (The builder application can help with this).
+
+[CookBook](CookBook.wiki.md) shows how to customize settings between production/development environments, and between groups.
+
+[CustomSource](CustomSource.wiki.md) shows how to set some file/source-specific options, or serve content from a PHP script or URL.
+
+### Hosting on Lighttpd
+
+Minify comes with Apache mod_rewrite rules, but this does the same for Lighttpd:
+
+```
+url.rewrite-once = ( "^/min/([a-z]=.*)" => "/min/index.php?$1" )
+```
+
+# Problems?
+
+See [CommonProblems](CommonProblems.wiki.md) and [Debugging](Debugging.wiki.md). You might also try running `server-info.php` in particular.
diff --git a/admin/survey/minify/docs/old/HowItWorks.wiki.md b/admin/survey/minify/docs/old/HowItWorks.wiki.md new file mode 100644 index 0000000..e1be599 --- /dev/null +++ b/admin/survey/minify/docs/old/HowItWorks.wiki.md @@ -0,0 +1,31 @@ +### Browsers, trust your cache
+
+In all responses a `Cache-Control` header is sent, telling the browser it doesn't need to "check in" with the server for some period of time. The ideal request is the one that never leaves the browser!
+
+### Convert a request to source objects
+
+When the browser makes a request like `/min/g=css`, Apache rewrites this to `/min/index.php?g=css`, which calls Minify's front controller.
+
+A separate controller then uses the querystring to establish a "sources" array, specifying exactly which objects (usually files) are to be included in the final output.
+
+### Try browser cache
+
+Minify finds the latest modification time of all the source objects (`filemtime` for files, so if you use a tool that doesn't update this, you might need to `touch` your modified files).
+
+If the browser has sent an `If-Modified-Since` header, and it's valid (the given date is older than the most recent source), then a 304 header is returned, execution stops, and the browser uses its cache copy.
+
+### Try server cache
+
+Minify generates a unique cache ID for the particular set of sources and their options. This is used to maintain a cache (file usually) of the final output.
+
+If the cache is "valid" (younger than the most recently modified source), then its content is sent along with a `Last-Modified` header with the most recent source's modification time, and execution stops.
+
+### Minification has to be done
+
+If any source is younger than the cache, the cache must be rebuilt from the minification process (slow, but infrequently done):
+
+Minify processes each source with a "minifier" function (determined by the content type of the sources and source-specific options), combines them to a single string, saves this to the cache object, then serves it with the `Last-Modified` header as sbove.
+
+#### Content encoding
+
+Minify actually stores a gzipped version of each output in a second cache object. If the browser supports it, Minify streams the pre-compressed content straight from cache (disk usually) to the browser.
\ No newline at end of file diff --git a/admin/survey/minify/docs/old/HttpCaching.wiki.md b/admin/survey/minify/docs/old/HttpCaching.wiki.md new file mode 100644 index 0000000..33e410c --- /dev/null +++ b/admin/survey/minify/docs/old/HttpCaching.wiki.md @@ -0,0 +1,63 @@ +# HTTP Caching in Minify
+
+## Conditional GET
+
+Minify sends all files with Last-Modified and ETag headers. If the browser requests a file again it will send along If-Modified-Since and If-None-Match headers. Minify checks these headers and, if the browser has the latest version, sends back only a slim "304 Not Modified" response (no content), telling the browser to use its cached file.
+
+## Expires Header
+
+Minify also sends Expires and Cache-Control: max-age headers, indicating that the file should be considered valid for a period of time. In future page views the browser will not re-request the file (unless the user refreshes), and instead will use the cached version.
+
+By default, Minify sends an Expires header for 1800 seconds (30 minutes) into the future (configurable via `$min_serveOptions['maxAge']`). This means your file changes may not be seen by users immediately after you make them. If your changes must be seen immediately, you should reduce max-age to 0, but note you will not get as much benefit, as browsers will still have to send requests **every time**.
+
+## Far-off Expires
+
+When pre-set groups are used and a number is appended to the minify URI (e.g. `/min/g=css&456`), then Minify sends an Expires date of 1 year in the future. This is great for caching, but places responsibility on your HTML pages. They _must_ change the number whenever a JS/CSS source file is updated, or the browser will not know to re-request the file. If you're generating your page with PHP, the [Minify\_groupUri](http://code.google.com/p/minify/source/browse/min/utils.php?r=222#11) utility function can make this easier to manage.
+
+# Using `HTTP_ConditionalGet` in other projects
+
+Minify uses the PHP class [HTTP\_ConditionalGet](http://code.google.com/p/minify/source/browse/lib/HTTP/ConditionalGet.php) to implement the conditional GET model. To use this in your own project you'll need the last modification time of your content (for a file, use [filemtime()](http://www.php.net/filemtime)), or a short hash digest of the content (something that changes when the content changes). You'll also want to consider if the content can be stored in public caches, or should only be stored in the user's browser.
+
+## When the last modification time is known
+
+In this example we implement conditional GET for a mostly-static PHP script. The browser needs to redownload the content only when the file is updated.
+
+```
+// top of file
+$cg = new HTTP_ConditionalGet(array(
+ 'isPublic' => true,
+ 'lastModifiedTime' => filemtime(__FILE__)
+));
+$cg->sendHeaders();
+if ($cg->cacheIsValid) { // 304 already sent
+ exit();
+}
+// rest of script
+```
+
+For the first request the browser's cache won't be valid, so the full script will execute, sending the full content. On the next, the cache will be valid and the sendHeaders() method will have already set the 304 header, so the script can be halted.
+
+There's also a shortcut static method for this:
+```
+HTTP_ConditionalGet::check(filemtime(__FILE__), true); // exits if client has cache
+// rest of script
+```
+
+## When last modification time isn't known
+
+Let's say you have an HTML page in a database, but no modification time. To reduce DB requests, you cache this content in a file/memory, but you'd also like to reduce bandwidth. In this case, what you can do is also cache a hash of the page along with the content. Now you can do this:
+
+```
+$cache = getCache();
+$cg = new HTTP_ConditionalGet(array(
+ 'isPublic' => true,
+ 'contentHash' => $cache['hash']
+));
+$cg->sendHeaders();
+if ($cg->cacheIsValid) { // 304 already sent
+ exit();
+}
+echo $cache['page'];
+```
+
+Although Last-Modified cannot be set, ETag will serve the same purposes in most browsers, allowing the conditional GET.
\ No newline at end of file diff --git a/admin/survey/minify/docs/old/ProjectGoals.wiki.md b/admin/survey/minify/docs/old/ProjectGoals.wiki.md new file mode 100644 index 0000000..7c3e521 --- /dev/null +++ b/admin/survey/minify/docs/old/ProjectGoals.wiki.md @@ -0,0 +1,13 @@ +## 1. Be easy to implement
+
+A PHP user should be able to quickly start serving JS/CSS much more optimally.
+
+## 2. Be extensible/versatile
+
+The user should be able to work Minify into an environment without modifying Minify's source. Right now this should be easy on the controller side, but the Minify class is static, which is fast, but may hinder extensibility.
+
+## 3. Be fast as possible
+
+With the release of 2.0.2 Minify will be much faster, outperforming even Apache's mod\_deflate (which apparently doesn't cache the encoded content like mod\_gzip does).
+
+Since testing has shown that [pre-encoding files and using type-maps on Apache is blazingly fast](http://mrclay.org/index.php/2008/06/03/pre-encoding-vs-mod_deflate/), Minify should work towards maintaining builds of pre-encoded files and letting Apache serve them. It's not clear if there's something similar to type-maps on lighttpd, but it's worth looking into.
\ No newline at end of file diff --git a/admin/survey/minify/docs/old/Security.wiki.md b/admin/survey/minify/docs/old/Security.wiki.md new file mode 100644 index 0000000..0836130 --- /dev/null +++ b/admin/survey/minify/docs/old/Security.wiki.md @@ -0,0 +1,15 @@ +This was quickly converted from an e-mail, please consider it "temporary".
+
+## Each file specified by `$_GET['f']` must:
+
+ * Have the [same extension, either "css" or "js"](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/lib/Minify/Controller/MinApp.php#66),
+ * Exist, and...
+ * Have a [realpath() within a whitelist of subdirectories](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/lib/Minify/Controller/Base.php#122).
+
+The default whitelist contains only DOCUMENT\_ROOT, but can be [specified](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/config.php#57).
+
+Then, a few more steps just to be paranoid:
+
+ * If a base was given by `$_GET['b']`, [it can't have ".."](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/lib/Minify/Controller/MinApp.php#84).
+ * `$_GET['f']` [must not contain "//", "\", or "./"](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/lib/Minify/Controller/MinApp.php#64).
+ * There can be [no duplicates](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/lib/Minify/Controller/MinApp.php#77) and only a [limited number of files](http://code.google.com/p/minify/source/browse/tags/release_2.1.1/min/config.php#73) can be specified.
\ No newline at end of file diff --git a/admin/survey/minify/docs/old/VersionTwo.wiki.md b/admin/survey/minify/docs/old/VersionTwo.wiki.md new file mode 100644 index 0000000..bf67528 --- /dev/null +++ b/admin/survey/minify/docs/old/VersionTwo.wiki.md @@ -0,0 +1,35 @@ +# Minify 2
+
+[Minify 2.0.0](http://code.google.com/p/minify/source/browse/tags/release_2.0.0/) was released May 22, 2008 and represents an architectural redesign of Minify's code and its usage. 2.0 is built as a library of classes allowing users to easily build customized minified-file servers; or add minification, HTTP encoding, or [conditional GET](http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers) to existing projects.
+
+The release includes 3 [example sites](http://code.google.com/p/minify/source/browse/tags/release_2.0.0/web/examples) to demostrate usage and [unit tests](http://code.google.com/p/minify/source/browse/tags/release_2.0.0/web/test/) you can run on your system.
+
+## Documentation
+
+Each PHP file is documented, but, for now, the [README file](http://code.google.com/p/minify/source/browse/tags/release_2.0.0/README) is the best reference for getting started with the library. This [blog post](http://mrclay.org/index.php/2008/03/27/minifying-javascript-and-css-on-mrclayorg/) may also give you some ideas.
+
+The best place for questions is the [minify Google group](http://groups.google.com/group/minify).
+
+### Included HTTP Classes
+
+The two HTTP utility classes, [HTTP\_ConditionalGet](http://code.google.com/p/minify/source/browse/lib/HTTP/ConditionalGet.php) and [HTTP\_Encoder](http://code.google.com/p/minify/source/browse/lib/HTTP/Encoder.php), are already fairly well-tested and include a set of test pages to see how they work. On the [Florida Automated Weather Network](http://fawn.ifas.ufl.edu/) site, these are used especially in scripts that serve data to our Flash components.
+
+Here's an example of using both to conditionally serve a text file gzipped:
+```
+$cg = new HTTP_ConditionalGet(array(
+ 'lastModifiedTime' => filemtime($filepath)
+ ,'isPublic' => true
+));
+$cg->sendHeaders();
+if ($cg->cacheIsValid) {
+ // client cache was valid, no content needed
+ exit();
+}
+require 'HTTP/Encoder.php';
+$he = new HTTP_Encoder(array(
+ 'content' => file_get_contents($filepath)
+ ,'type' => 'text/plain'
+));
+$he->encode();
+$he->sendAll();
+```
\ No newline at end of file |