Remove render blocking javascript in rails with react-rails gem -


i have ruby on rails app. views using react-rails gem. want improve pagespeed through google pagespeed. main problem remove render-blocking javascript added async: true javascript_include_tag helper method. when refresh site have blank white window browser these messages inside console:

referenceerror: $ not defined    $(document).ready(ready); referenceerror: jquery not defined    }(jquery);  referenceerror: jquery not defined    })( jquery );  referenceerror: react not defined     this.about = react.createclass({ 

my applicaton.js file:

// //= require jquery //= require jquery_ujs //= require turbolinks //= require bootstrap-sprockets //= require react //= require react_ujs //= require semantic-ui //= require components //= reqiore custom //= require_tree .  var ready; ready = function() {  };  $(document).ready(ready); $(document).on('page:load', ready); 

what need in order remove blocking javascript?

since virtually on page dependent on jquery, successful page rendering needs jquery loaded start. therefore in experience there no way around blocking javascript.

from user's perspective, putting in lot of work prevent jquery blocking may allow dom load, lot of jumping around after jquery , related plugins have loaded dom gets rewritten, making experience worse marginally longer page load.

overall, i'd focus efforts on ensuring jquery , related js , css files delivered through cdn, can benefit http pulling second domain in parallel primary, , ensure nothing break browser caching of jquery , other assets not block on subsequent request.

edit

i meant mention worth testing assets precompiled (which necessary anyway if using cdn), switching off asset live compilation missing items with

config.assets.compile = false 

this prevent missing assets causing confusing delays, , possibly invalid compilations once live.

an additional note regarding serving assets web server:

according http://guides.rubyonrails.org/asset_pipeline.html

4.1.1 far-future expires header

precompiled assets exist on file system , served directly web server. not have far-future headers default, benefit of fingerprinting you'll have update server configuration add headers.

for apache:

# expires* directives requires apache module # `mod_expires` enabled. <location /assets/>   # use of etag discouraged when last-modified present   header unset etag   fileetag none   # rfc says cache 1 year   expiresactive on   expiresdefault "access plus 1 year" </location> 

for nginx:

location ~ ^/assets/ {   expires 1y;   add_header cache-control public;    add_header etag "";   break; } 

finally, make sure test running on server mimics eventual production environment, rails development servers not going provide same responsiveness.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -