Skip to content

Instantly share code, notes, and snippets.

@Benjaminpjacobs
Last active June 1, 2017 14:54
Show Gist options
  • Save Benjaminpjacobs/5f4fe82718f49f9016f40a2d16db51a4 to your computer and use it in GitHub Desktop.
Save Benjaminpjacobs/5f4fe82718f49f9016f40a2d16db51a4 to your computer and use it in GitHub Desktop.
Asset Pipeline Overview

RAILS_ENV=production rails s - Runs our production environemnt locally gem 'Figaro' allows us to run secret keys creates application.yml file add SECRET_KEY_BASE as key paired to secret hash rake secret = gives us secret hash

Erros in Production Log

RAILS_SERVE_STATIC_FILES: true goes in application.yml

Rails assets:precompile - precompiles assets for browser Rails assets:clobber - removes precompiled assets so we can update

** What does it mean to precompile files?

Moving all asset files to one location so they can be compiled and cached ahead of time and not every time the app boots. Compiling and precompiling turns our dynamic languages into what the browser can understand locally. So precompiling locally creates browser friendly files in advance.

Take code you wrote in a language the browser won't understand and compile them down into a single string file in a language the browser can read.

** What does this have to do with Coffeescript and Sass files?

Coffescript and Sass are examples of dynamic language syntax that needs to be converted at compilation time. So precompiling these improves performance and browser response.

** Does it only have to do with Coffeescript and Sass files?

No. It most likely effects anything that is not specifically CSS, HTML or Javascript.

** What does it mean to minify files? Why would we want to minify files?

Combines files that are split into partials, or otherwise divided, removes whitespace thereby reducing byte size(file size), reinterpolates variables in dynamic languages like javascript, thereby making it more efficient and readable for the browser. Minification allows you to write in readable code.

** What does Sprockets do and how does it fit into the precompile / minify puzzle?

Sprockets concatenates all JavaScript files into one master .js file and all CSS files into one master .css file. It is effectively what handles minification.

** Open up the code for application.js in your text editor.Why are these not the same?

Because sprockets is concatenating all our JS files in the browser.

** What is a manifest (in terms of the asset pipeline)? Where can you find two manifests in Catch ‘em All?

Application.css and Application.js are both manifests that list all the relevant files that will need to be loaded into the browser

** In regular HTML files, we import CSS files with . How is this done in a Rails project? Where do you see this line in Catch ‘em All?

** How is a digest or fingerprint used on assets for caching purposes?

If the fingerprint is different from what is cached in the browser, it knows to update. Otherwise it uses the cached file and speeds up performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment