The Asset Pipeline - Ruby on Rails Guides - 0 views
-
provides a framework to concatenate and minify or compress JavaScript and CSS assets
-
adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB
- ...80 more annotations...
-
Starting with version 3.1, Rails defaults to concatenating all JavaScript files into one master .js file and all CSS files into one master .css file
-
In production, Rails inserts an MD5 fingerprint into each filename so that the file is cached by the web browser
-
The technique sprockets uses for fingerprinting is to insert a hash of the content into the name, usually at the end.
-
The sass-rails gem is automatically used for CSS compression if included in Gemfile and no config.assets.css_compressor option is set.
-
When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (whether at CDNs, at ISPs, in networking equipment, or in web browsers) to keep their own copy of the content
-
app/assets is for assets that are owned by the application, such as custom images, JavaScript files or stylesheets.
-
lib/assets is for your own libraries' code that doesn't really fit into the scope of the application or those libraries which are shared across applications.
-
vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.
-
By default these files will be ready to use by your application immediately using the require_tree directive.
-
By default, this means the files in app/assets take precedence, and will mask corresponding paths in lib and vendor
-
if you add an erb extension to a CSS asset (for example, application.css.erb), then helpers like asset_path are available in your CSS rules
-
If you add an erb extension to a JavaScript asset, making it something such as application.js.erb, then you can use the asset_path helper in your JavaScript code
-
data URI — a method of embedding the image data directly into the CSS file — you can use the asset_data_uri helper.
-
Sprockets will also look through the paths specified in config.assets.paths, which includes the standard application paths and any paths added by Rails engines.
-
sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.
-
The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output.
-
manifest files contain directives — instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file.
-
Directives are processed top to bottom, but the order in which files are included by require_tree is unspecified.
-
You need not supply the extensions explicitly. Sprockets assumes you are requiring a .js file when done from within a .js file
-
Rails 4 creates both app/assets/javascripts/application.js and app/assets/stylesheets/application.css regardless of whether the --skip-sprockets option is used when creating a new rails application.
-
Additional layers of preprocessing can be requested by adding other extensions, where each extension is processed in a right-to-left manner
-
In development mode, assets are served as separate files in the order they are specified in the manifest file.
-
when these files are requested they are processed by the processors provided by the coffee-script and sass gems and then sent back to the browser as JavaScript and CSS respectively.
-
By default Rails assumes that assets have been precompiled and will be served as static assets by your web server
-
If you set config.assets.initialize_on_precompile to false, be sure to test rake assets:precompile locally before deploying
-
By default Rails assumes assets have been precompiled and will be served as static assets by your web server.
-
The X-Sendfile header is a directive to the web server to ignore the response from the application, and instead serve a specified file from disk