MIN.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. The files in the /min/ directory represent the default Minify setup designed to ease
  2. integration with your site. This app will combine and minify your Javascript or
  3. CSS files and serve them with HTTP compression and cache headers.
  4. RECOMMENDED
  5. It's recommended to edit /min/config.php to set $min_cachePath to a writeable
  6. (by PHP) directory on your system. This will improve performance.
  7. GETTING STARTED
  8. The quickest way to get started is to use the Minify URI Builder application
  9. on your website: http://example.com/min/builder/
  10. MINIFYING A SINGLE FILE
  11. Let's say you want to serve this file:
  12. http://example.com/wp-content/themes/default/default.css
  13. Here's the "Minify URL" for this file:
  14. http://example.com/min/?f=wp-content/themes/default/default.css
  15. In other words, the "f" argument is set to the file path from root without the
  16. initial "/". As CSS files may contain relative URIs, Minify will automatically
  17. "fix" these by rewriting them as root relative.
  18. COMBINING MULTIPLE FILES IN ONE DOWNLOAD
  19. Separate the paths given to "f" with commas.
  20. Let's say you have CSS files at these URLs:
  21. http://example.com/scripts/jquery-1.2.6.js
  22. http://example.com/scripts/site.js
  23. You can combine these files through Minify by requesting this URL:
  24. http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js
  25. SIMPLIFYING URLS WITH A BASE PATH
  26. If you're combining files that share the same ancestor directory, you can use
  27. the "b" argument to set the base directory for the "f" argument. Do not include
  28. the leading or trailing "/" characters.
  29. E.g., the following URLs will serve the exact same content:
  30. http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js,scripts/home.js
  31. http://example.com/min/?b=scripts&f=jquery-1.2.6.js,site.js,home.js
  32. MINIFY URLS IN HTML
  33. In HTML files, don't forget to replace any "&" characters with "&".
  34. SPECIFYING ALLOWED DIRECTORIES
  35. By default, Minify will serve any *.css/*.js files within the DOCUMENT_ROOT. If
  36. you'd prefer to limit Minify's access to certain directories, set the
  37. $min_serveOptions['minApp']['allowDirs'] array in config.php. E.g. to limit
  38. to the /js and /themes/default directories, use:
  39. $min_serveOptions['minApp']['allowDirs'] = array('//js', '//themes/default');
  40. GROUPS: NICER URLS
  41. For nicer URLs, edit groupsConfig.php to pre-specify groups of files
  42. to be combined under preset keys. E.g., here's an example configuration in
  43. groupsConfig.php:
  44. return array(
  45. 'js' => array('//js/Class.js', '//js/email.js')
  46. );
  47. This pre-selects the following files to be combined under the key "js":
  48. http://example.com/js/Class.js
  49. http://example.com/js/email.js
  50. You can now serve these files with this simple URL:
  51. http://example.com/min/?g=js
  52. GROUPS: SPECIFYING FILES OUTSIDE THE DOC_ROOT
  53. In the groupsConfig.php array, the "//" in the file paths is a shortcut for
  54. the DOCUMENT_ROOT, but you can also specify paths from the root of the filesystem
  55. or relative to the DOC_ROOT:
  56. return array(
  57. 'js' => array(
  58. '//js/file.js' // file within DOC_ROOT
  59. ,'//../file.js' // file in parent directory of DOC_ROOT
  60. ,'C:/Users/Steve/file.js' // file anywhere on filesystem
  61. )
  62. );
  63. COMBINE MULTIPLE GROUPS AND FILES IN ONE URL
  64. E.g.: http://example.com/min/?g=js&f=more/scripts.js
  65. Separate group keys with commas:
  66. http://example.com/min/?g=baseCss,css1&f=moreStyles.css
  67. FAR-FUTURE EXPIRES HEADERS
  68. Minify can send far-future (one year) Expires headers. To enable this you must
  69. add a number or the parameter "v" to the querystring (e.g. /min/?g=js&1234 or
  70. /min/?g=js&v=1234) and alter it whenever a source file is changed. If you have a
  71. build process you can use a build/source control revision number.
  72. You can alternately use the utility function Minify_getUri() to get a "versioned"
  73. Minify URI for use in your HTML. E.g.:
  74. <?php
  75. require $_SERVER['DOCUMENT_ROOT'] . '/min/utils.php';
  76. $jsUri = Minify_getUri('js'); // a key in groupsConfig.php
  77. echo "<script src='{$jsUri}'></script>";
  78. $cssUri = Minify_getUri(array(
  79. '//css/styles1.css'
  80. ,'//css/styles2.css'
  81. )); // a list of files
  82. echo "<link rel=stylesheet href='{$cssUri}'>";
  83. STORING CONFIG FILES OUTSIDE THE MINIFY DIRECTORY
  84. It is possible to store config files (min/config.php, min/config-test.php,
  85. min/groupsConfig.php) in a custom directory outside the Minify directory. This is
  86. useful if you wish to include Minify as an external dependency inside another
  87. project via SVN external or Git submodule inclusion.
  88. For example, let's assume you have a Minify directory "min" in your site root. Then
  89. you could create a new directory called "min-configs" in the site root. Copy any
  90. config files you wish to modify to "min-configs", and modify as desired.
  91. Then create a new file, for example "min.php" in your site root. The contents of
  92. this file could look like this:
  93. <?php
  94. $customConfigDirectory = dirname(__FILE__) . '/min-configs';
  95. $min_customConfigPaths = array(
  96. 'base' => $customConfigDirectory . '/config.php',
  97. 'test' => $customConfigDirectory . '/config-test.php',
  98. 'groups' => $customConfigDirectory . '/groupsConfig.php'
  99. );
  100. include_once 'min/index.php';
  101. You would then reference min.php in your JS and CSS links instead of min/index.php.
  102. This method will affect those using the Minify_getUri() function. You will need
  103. to add options to calls to that function, e.g.:
  104. <?php
  105. require $_SERVER['DOCUMENT_ROOT'] . '/min/utils.php';
  106. $jsUri = Minify_getUri('//js/file.js', array('minAppUri' => '/min.php'));
  107. echo "<script src='{$jsUri}'></script>";
  108. DEBUG MODE
  109. In debug mode, instead of compressing files, Minify sends combined files with
  110. comments prepended to each line to show the line number in the original source
  111. file. To enable this, set $min_allowDebugFlag to true in config.php and append
  112. "&debug=1" to your URIs. E.g. /min/?f=script1.js,script2.js&debug=1
  113. Known issue: files with comment-like strings/regexps can cause problems in this mode.
  114. QUESTIONS?
  115. http://groups.google.com/group/minify