Giter Club home page Giter Club logo

asset_pipeline_poem's Introduction

Asset Pipeline Poem

Objectives
Explore the assets pipeline in rails
Practice structuring require statements
Precompile compressed javascript assets

Terms:

  • Manifest
  • Pre/compilation
  • Concatenation
  • Compression / Minification
  • Browser Caching
  • MD5 fingerprint

##Instructions: Your goal is to reconstruct a simple poem.

  • Clone this repo
    • Note that this rails app does not have a database.
  • Run your server and open "/". You should see a jumbled poem.

When you're done make changes, the homepage should look like this (with the poem in the correct order and styled correctly):

goal

Rules

  • You are not allowed to modify any files.
  • You are only allowed to update the manifests in:
    • app/assets/javascripts/application.js
      • e.g. //= require roses-are-red
    • app/assets/stylesheets/application.css
      • e.g. *= require layout
  • Try not to use require_tree . anywhere.

Part 1. Using the Asset Pipeline

The assets you want live in the following locations, inside of your rails application directory:

app/                    # application specific code
    assets/
        images/
        javascripts/
        stylesheets/
lib/                    # custom libraries
    assets/
        javascripts/
        stylesheets/
vendor/                 # third party libraries
    assets/
        javascripts/
        stylesheets/

Each directory has a specific use-case. The files you want are scattered across them. Your goal is to find all the files and require them in the correct order!

Part 2. Precompilation

Your solution should also work in production!

First, we need to precompile our assets.

rake assets:precompile

After running rake assets:precompile, your concatenated/compressed assets will live in:

public/
    assets/

Next, we need to run our server in production:

SECRET_KEY_BASE=shhhh RAILS_SERVE_STATIC_FILES=true rails server -e production

Now when you use "view source" in the chrome console, you should see one application-12345.js file, and one application-abcde.css file. That last bit is called a "fingerprint" and it's used for caching.

Whenever you change a javascript or css file, you need to:

  1. precompile your assets again
  2. restart your server

The fingerprint will change whenever the file changes. Use view-source to see it!

When in doubt, start fresh:

  • Delete tmp/cache/assets/
  • Delete public/assets/
  • ( OR, you can just run: rake assets:clobber )
  • And restart your server!!!

##Bonuses: Note that reset.css is being included using a CDN. It's a quick and dirty way of including it, but let's save it locally:

  1. Find and copy the current reset.css url (see views/layouts/application.html.erb)
  2. cd vendor/assets/stylesheets/
  3. curl -vs RESET_CSS_URL > reset.css
  4. Finally, delete the old cdn link, and "require" the new reset in your application.css manifest.

##Reading http://guides.rubyonrails.org/asset_pipeline.html https://github.com/rails/sprockets#sprockets-directives

asset_pipeline_poem's People

Contributors

nathanallen avatar justincastilla avatar

Watchers

James Cloos avatar Alex Rao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.