Javascript files - markstory/asset_compress GitHub Wiki

Javascript

Javascript makes the world go around. But too many files makes for slow, sad and sluggish pages. Asset Compress provides a few features for making Javascript faster and more compact.

  • stripComments stripComments can be enabled in your ini file. This will strip all comments out of your javascript file reducing their size and hiding your possibly embarrassing remarks.
  • filters filters can be configured to maximize compression by passing files into a minifier like JSMin
  • directives help you manage dependencies and allow you to create organized source code without worrying about having the client download a bazillion files.

Javascript directives

Asset Compress implements several features from sprockets. This helps you write more manageable source code with less insanity.

//= require

//= require allows you to create dependencies between to javascript files. It works very similar to how require works in PHP. Files can be required in from any of the searchPaths configured in your ini file. Each file will only be included once into each build file by Asset Compress, so there is no need to worry about double including a file into a build file.

There are two flavours of //= require. The first is same directory requiring, which loads other files from the same directory or higher directories from the current file.

//= require "other_class"

Will inline ./other_class.js where the require statement was. other_class.js will also be processed for any require directives as well. The second type of require is all directory requiring. All directory requiring will include the first file with the matching name on any of the defined searchPaths.

//= require <my_library>

Would include the first my_library.js file found on any searchPath.

Note

The provides directive supported by sprockets is not implemented by Asset Compress.

Filters

Filters can be configured in your Configuration and are a set of classes implementing an interface that are applied to processed assets in the order they are declared. Filters are great for compressing output with a tool like JSMin. More information on filters

⚠️ **GitHub.com Fallback** ⚠️