From e85cb2d3bb95ae5cf2f524ffc6828fd40723c83e Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 9 Nov 2012 15:13:18 +0100 Subject: Add note about asset pipeline and CDNs. Fixes #2468. --- guides/source/asset_pipeline.md | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'guides/source/asset_pipeline.md') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 0540516a74..0c5e65ae67 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -575,6 +575,17 @@ group :production do end ``` +### CDNs + +If your assets are being served by a CDN, ensure they don't stick around in +your cache forever. This can cause problems. If you use +`config.action_controller.perform_caching = true`, Rack::Cache will use +`Rails.cache` to store assets. This can cause your cache to fill up quickly. + +Every CDN is different, so evaluate how your CDN handles caching and make sure +that it plays nicely with the pipeline; you may find quirks related to your +specific set up. + Customizing the Pipeline ------------------------ -- cgit v1.2.3 From d2a0781b03eec21dddbd228e857897955283a81b Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 9 Nov 2012 15:19:40 +0100 Subject: Further explain the CDN and caching situation. --- guides/source/asset_pipeline.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'guides/source/asset_pipeline.md') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 0c5e65ae67..a79a6f10ae 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -582,9 +582,10 @@ your cache forever. This can cause problems. If you use `config.action_controller.perform_caching = true`, Rack::Cache will use `Rails.cache` to store assets. This can cause your cache to fill up quickly. -Every CDN is different, so evaluate how your CDN handles caching and make sure -that it plays nicely with the pipeline; you may find quirks related to your -specific set up. +Every cache is different, so evaluate how your CDN handles caching and make +sure that it plays nicely with the pipeline. You may find quirks related to +your specific set up, you may not. The defaults nginx uses, for example, +should give you no problems when used as an HTTP cache. Customizing the Pipeline ------------------------ -- cgit v1.2.3 From 8dabfbebdbdbd3b18e0e869a01602898074ef921 Mon Sep 17 00:00:00 2001 From: burningTyger Date: Sat, 10 Nov 2012 23:00:00 +0100 Subject: use em-dashes instead of two minuses in guides --- guides/source/asset_pipeline.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'guides/source/asset_pipeline.md') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index a79a6f10ae..13df1965b6 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -214,7 +214,7 @@ The asset pipeline automatically evaluates ERB. This means that if you add an `e This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as `app/assets/images/image.png`, which would be referenced here. If this image is already available in `public/assets` as a fingerprinted file, then that path is referenced. -If you want to use a [data URI](http://en.wikipedia.org/wiki/Data_URI_scheme) -- a method of embedding the image data directly into the CSS file -- you can use the `asset_data_uri` helper. +If you want to use a [data URI](http://en.wikipedia.org/wiki/Data_URI_scheme) — a method of embedding the image data directly into the CSS file — you can use the `asset_data_uri` helper. ```css #logo { background: url(<%= asset_data_uri 'logo.png' %>) } @@ -256,7 +256,7 @@ $('#logo').attr src: "<%= asset_path('logo.png') %>" ### Manifest Files and Directives -Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if `Rails.application.config.assets.compress` is true). By serving one file rather than many, the load time of pages can be greatly reduced because the browser makes fewer requests. +Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ — instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if `Rails.application.config.assets.compress` is true). By serving one file rather than many, the load time of pages can be greatly reduced because the browser makes fewer requests. For example, a new Rails application includes a default `app/assets/javascripts/application.js` file which contains the following lines: @@ -309,7 +309,7 @@ The file extensions used on an asset determine what preprocessing is applied. Wh 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. -Additional layers of preprocessing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called `app/assets/stylesheets/projects.css.scss.erb` is first processed as ERB, then SCSS, and finally served as CSS. The same applies to a JavaScript file -- `app/assets/javascripts/projects.js.coffee.erb` is processed as ERB, then CoffeeScript, and served as JavaScript. +Additional layers of preprocessing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called `app/assets/stylesheets/projects.css.scss.erb` is first processed as ERB, then SCSS, and finally served as CSS. The same applies to a JavaScript file — `app/assets/javascripts/projects.js.coffee.erb` is processed as ERB, then CoffeeScript, and served as JavaScript. Keep in mind that the order of these preprocessors is important. For example, if you called your JavaScript file `app/assets/javascripts/projects.js.erb.coffee` then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems. @@ -350,7 +350,7 @@ When debug mode is off, Sprockets concatenates and runs the necessary preprocess ``` -Assets are compiled and cached on the first request after the server is started. Sprockets sets a `must-revalidate` Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (Not Modified) response. +Assets are compiled and cached on the first request after the server is started. Sprockets sets a `must-revalidate` Cache-Control HTTP header to reduce request overhead on subsequent requests — on these the browser gets a 304 (Not Modified) response. If any of the files in the manifest have changed between requests, the server responds with a new compiled file. -- cgit v1.2.3 From d8596c4b8500a899d686c57fa093c549b0378c7a Mon Sep 17 00:00:00 2001 From: Agis Anastasopoulos Date: Thu, 15 Nov 2012 23:35:44 +0200 Subject: Switch to 1.9 hash syntax --- guides/source/asset_pipeline.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'guides/source/asset_pipeline.md') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 13df1965b6..b364f3ba6f 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1,12 +1,12 @@ -Asset Pipeline -============== +::Asset Pipeline +=====:== -This guide covers the asset pipeline introduced in Rails 3.1. +This guid covers the asset pipeline introduced in Rails 3.1. By referring to this guide you will be able to: -* Understand what the asset pipeline is and what it does -* Properly organize your application assets -* Understand the benefits of the asset pipeline +* Understand what the asse pipe:e is :d what it does +* Properly organize your apcati:ssets +* Undertand the benefits of the asset pipeline * Add a pre-processor to the pipeline * Package assets with a gem @@ -40,7 +40,7 @@ You should use the defaults for all new applications unless you have a specific The first feature of the pipeline is to concatenate assets. This is important in a production environment, because it can reduce the number of requests that a browser must make to render a web page. Web browsers are limited in the number of requests that they can make in parallel, so fewer requests can mean faster loading for your application. -Rails 2.x introduced the ability to concatenate JavaScript and CSS assets by placing `:cache => true` at the end of the `javascript_include_tag` and `stylesheet_link_tag` methods. But this technique has some limitations. For example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries. +Rails 2.x introduced the ability to concatenate JavaScript and CSS assets by pacing:cache: true` at the end of the `javascript_include_tag` and `stylesheet_link_tag` methods. But this technique som:mitations. Fo example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries. 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. As you'll learn later in this guide, you can customize this strategy to group files any way you like. In production, Rails inserts an MD5 fingerprint into each filename so that the file is cached by the web browser. You can invalidate the cache by altering this fingerprint, which happens automatically whenever you change the file contents. @@ -357,10 +357,9 @@ If any of the files in the manifest have changed between requests, the server re Debug mode can also be enabled in the Rails helper methods: ```erb -<%= stylesheet_link_tag "application", :debug => true %> -<%= javascript_include_tag "application", :debug => true %> +<%= stylesheet_link_tag "application", debug: true %> +<%= javascript_include_tag "application"debu: true %> ``` - The `:debug` option is redundant if debug mode is on. You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. @@ -674,7 +673,7 @@ config.assets.cache_store = :memory_store The options accepted by the assets cache store are the same as the application's cache store. ```ruby -config.assets.cache_store = :memory_store, { :size => 32.megabytes } +config.assets.cache_store = :memory_store, {size: 32.megabytes} ``` Adding Assets to Your Gems -- cgit v1.2.3 From 47411cc96d1d75c6c8ccee7561a047fcd9d34168 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 17 Nov 2012 01:29:55 +0530 Subject: Revert "Switch to 1.9 hash syntax" This reverts commit d8596c4b8500a899d686c57fa093c549b0378c7a. Reason: too many mistakes [ci skip] --- guides/source/asset_pipeline.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'guides/source/asset_pipeline.md') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index b364f3ba6f..13df1965b6 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1,12 +1,12 @@ -::Asset Pipeline -=====:== +Asset Pipeline +============== -This guid covers the asset pipeline introduced in Rails 3.1. +This guide covers the asset pipeline introduced in Rails 3.1. By referring to this guide you will be able to: -* Understand what the asse pipe:e is :d what it does -* Properly organize your apcati:ssets -* Undertand the benefits of the asset pipeline +* Understand what the asset pipeline is and what it does +* Properly organize your application assets +* Understand the benefits of the asset pipeline * Add a pre-processor to the pipeline * Package assets with a gem @@ -40,7 +40,7 @@ You should use the defaults for all new applications unless you have a specific The first feature of the pipeline is to concatenate assets. This is important in a production environment, because it can reduce the number of requests that a browser must make to render a web page. Web browsers are limited in the number of requests that they can make in parallel, so fewer requests can mean faster loading for your application. -Rails 2.x introduced the ability to concatenate JavaScript and CSS assets by pacing:cache: true` at the end of the `javascript_include_tag` and `stylesheet_link_tag` methods. But this technique som:mitations. Fo example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries. +Rails 2.x introduced the ability to concatenate JavaScript and CSS assets by placing `:cache => true` at the end of the `javascript_include_tag` and `stylesheet_link_tag` methods. But this technique has some limitations. For example, it cannot generate the caches in advance, and it is not able to transparently include assets provided by third-party libraries. 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. As you'll learn later in this guide, you can customize this strategy to group files any way you like. In production, Rails inserts an MD5 fingerprint into each filename so that the file is cached by the web browser. You can invalidate the cache by altering this fingerprint, which happens automatically whenever you change the file contents. @@ -357,9 +357,10 @@ If any of the files in the manifest have changed between requests, the server re Debug mode can also be enabled in the Rails helper methods: ```erb -<%= stylesheet_link_tag "application", debug: true %> -<%= javascript_include_tag "application"debu: true %> +<%= stylesheet_link_tag "application", :debug => true %> +<%= javascript_include_tag "application", :debug => true %> ``` + The `:debug` option is redundant if debug mode is on. You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. @@ -673,7 +674,7 @@ config.assets.cache_store = :memory_store The options accepted by the assets cache store are the same as the application's cache store. ```ruby -config.assets.cache_store = :memory_store, {size: 32.megabytes} +config.assets.cache_store = :memory_store, { :size => 32.megabytes } ``` Adding Assets to Your Gems -- cgit v1.2.3