My favorites | Sign in
Logo
                
Search
for
Updated Dec 13 (5 days ago) by st...@mrclay.org
Labels: Featured, Phase-Support
CommonProblems  
Common Problems using Minify

If this page doesn't help, please post a question on our Google group.

URIs are re-written incorrectly in CSS output

See UriRewriting.

Files aren't cached in IE6

If you have 2.1.3:

  1. Open /min/lib/HTTP/Encoder.php
  2. On line 62, change false to true.

Details on the issue page, but basically this allows sending gzipped content to IE6 and (more importantly) allows IE6 to cache it.

Builder Fails / 400 Errors

With URLs like /min/f=..., Minify is paranoid about not serving files outside of $_SERVER['DOCUMENT_ROOT']. If you're trying to serve files that are actually symlinks (or in a symlinked folder) to files outside of the DOC_ROOT, Minify won't allow it by default.

Example

Your DOC_ROOT is /var/www, but /var/www/css is actually a symlink to /var/shared/css. To serve /min/f=css/site.css, we must explicitly add the symlink target folder to the allowDirs option:

$min_serveOptions['allowDirs'] = array(
    '//', // DOC_ROOT
    '/var/shared/css'
);

Now Minify can serve files whose realpath() is in /var/shared/css.

Dealing with Javascript errors

Minify currently uses JSMin to remove whitespace from Javascript. Although Minify's JSMin has been patched beyond Douglas Crockford's original, errors can still be introduced, e.g. in scripts that rely on semicolon insertion or other unusual syntax. To avoid problems, in general:

  • When available, use pre-compressed versions of Javascript libraries (generally JSMin will not break code output by the more advanced Rhino-based compressors like YUI Compressor), or use a Google-hosted version and reserve Minify for serving plugins and user code.
  • Try debug mode to check your files for errors. Debug mode can introduce its own errors, but is generally reliable. The comment at the beginning of the line of the error will tell you the line number in the original source file.
  • In a custom group, you can specify a file to have no minifier (HTTP compression will still be used).
  • If you have Java on your web host, you can use the wrapper for YUI Compressor instead of JSMin. This thread shows how a user has done this.

Scriptaculous

Scriptaculous 1.8.2 (and probably all 1.x) has an autoloader script 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&amp;f=effects.js,dragdrop.js" type="text/javascript"></script>
<script type="text/javascript">
/* DragDrop and Effects modules can be used here. */
</script>

Cache files won't update

If you upload files using Coda or Transmit or from a Windows PC to a non-Windows server, your new files may end up with the wrong timestamp on the server, confusing the cache system.

Setting the $min_uploaderHoursBehind option in config.php can compensate for this.

WinSCP has a Daylight Saving Time option that can prevent this issue.

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 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? Use UTF-8.

@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 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.

// in 2.1.1 and previous
return /'/;   // JSMin throws error
return (/'/); // no error

See Also



Sign in to add a comment
Hosted by Google Code