Asset fingerprinting is a clever way to force browsers to keep cached assets up-to-date. What happens is that Asset Pipeline looks at each asset and it develops an MD5 Hash for that asset. That is, it takes the entire contents of the asset and from that distills it down to a single string. And then it pins that string to the end of the file name. And it's called a fingerprint. The reason it does that is because the asset file is gonna be cached by the user's web browser. But whenever something about the file changes, the MD5 Hash will change, and that means that the file name will change.
And you'll give up all of those advantages that we just talked about with using Asset Pipeline. The way that Asset Pipeline knows which files to concatenate together is through the use of something called the manifest file. The manifest file contains directives telling Asset Pipeline which assets should be included and in what order. Asset Pipeline loads the files in the manifest, processes them if necessary, concatenates them into a single file, and then compresses that file into one. This creates a single smaller stylesheet, which can be cached by a user's browser, and which can contain styles from many parts of the site.
It's generally better to serve one file to the browser instead of many files. But at the same time, we have the ability to develop using many files. We can separate our CSS up into 20 different files if we want, and they'll all get compressed into one file to serve to the user. So there is an important distinction about the way that Asset Pipeline works with the development versus production. When we are in development, Asset Pipeline skips the concatenation, the compression and the fingerprinting and only does the file processing. If we're using SAS, CoffeeScript or ERB, those will still be interpreted.
But it won't do all the other steps. There are a couple of reasons why that's true. The main one being, that files are changing frequently during development, and so they need reprocessing but it's not worth spinning the extra energy on concatenating, compressing and fingerprinting. When we're in production, though, Asset Pipeline actually skips all of those steps, and it doesn't do any asset processing. That may be surprising, but the reason why is because Rails assumes that those assets have already been precompiled for it. And that's a necessary step when we're deploying using Asset Pipeline, is we have to actually create those files.
We have to take the manifest file, and create those fingerprinted files for it. Those typically reside in public/assets. So this would be an example of how application dot css would be turned into public/assets/application with a fingerprint after it dot css. And then the gzipped version as well. So how do we do this precompilation? Well, you wanna make sure that your Rails environment is set to production, and then from the root of your Rails application, on the Command line, you could type: bundle exec rails assets colon precompile.
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.