Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Asset Pipeline for Dummies

Asset Pipeline for Dummies

Delve deep into the Rails asset pipeline.. well, let's just figure it out together!

Eric Berry

April 24, 2012
Tweet

More Decks by Eric Berry

Other Decks in Programming

Transcript

  1. Sprockets performs the asset packaging which takes the assets from

    all the specified paths, compiles them together and places them in the target path (public/assets).
  2. Tilt is the template engine that Sprockets uses. This allows

    file types like scss and erb to be used in the asset pipeline.
  3. app/assets is for assets that are owned by the application,

    such as custom images, JavaScript files or stylesheets.
  4. 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.
  5. 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.
  6. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once.
  7. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once. • include [path] works like require, but inserts the contents of the specified source file even if it has already been included or required.
  8. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once. • include [path] works like require, but inserts the contents of the specified source file even if it has already been included or required. • require_directory [path] requires all source files of the same format in the directory specified by path. Files are required in alphabetical order.
  9. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once. • include [path] works like require, but inserts the contents of the specified source file even if it has already been included or required. • require_directory [path] requires all source files of the same format in the directory specified by path. Files are required in alphabetical order. • require_tree [path] works like require_directory, but operates recursively to require all files in all subdirectories of the directory specified by path.
  10. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once. • include [path] works like require, but inserts the contents of the specified source file even if it has already been included or required. • require_directory [path] requires all source files of the same format in the directory specified by path. Files are required in alphabetical order. • require_tree [path] works like require_directory, but operates recursively to require all files in all subdirectories of the directory specified by path. • require_self tells Sprockets to insert the body of the current source file before any subsequent require or include directives.
  11. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once. • include [path] works like require, but inserts the contents of the specified source file even if it has already been included or required. • require_directory [path] requires all source files of the same format in the directory specified by path. Files are required in alphabetical order. • require_tree [path] works like require_directory, but operates recursively to require all files in all subdirectories of the directory specified by path. • require_self tells Sprockets to insert the body of the current source file before any subsequent require or include directives. • depend_on [path] declares a dependency on the given path without including it in the bundle. This is useful when you need to expire an asset’s cache in response to a change in another file.
  12. • require [path] inserts the contents of the asset source

    file specified by path. If the file is required multiple times, it will appear in the bundle only once. • include [path] works like require, but inserts the contents of the specified source file even if it has already been included or required. • require_directory [path] requires all source files of the same format in the directory specified by path. Files are required in alphabetical order. • require_tree [path] works like require_directory, but operates recursively to require all files in all subdirectories of the directory specified by path. • require_self tells Sprockets to insert the body of the current source file before any subsequent require or include directives. • depend_on [path] declares a dependency on the given path without including it in the bundle. This is useful when you need to expire an asset’s cache in response to a change in another file. • stub [path] allows dependency to be excluded from the asset bundle. The path must be a valid asset and may or may not already be part of the bundle. Once stubbed, it is blacklisted and can’t be brought back by any other require.
  13. Files must belong in their respective paths. For example, all

    JavaScript files must be in a javascripts folder within an asset path.
  14. Files must belong in their respective paths. For example, all

    JavaScript files must be in a javascripts folder within an asset path. The truth is that the paths (stylesheets, javascripts, images) are only there for organization. You can have all the assets in a single folder or in a hundred.
  15. Sass files need to use *erb* extension to allow for

    asset path inclusions within the files.
  16. Sass files need to use *erb* extension to allow for

    asset path inclusions within the files. The truth is that sass-rails provides -url and -path helpers for the following asset types: image, font, video, audio, JavaScript and stylesheet.
  17. faq