最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - stylesheet async with rails - Stack Overflow

programmeradmin0浏览0评论

I want to load my javascripts and stylesheets async to have a better loading performance; with javascript I know I can load the javascripts async with:

javascript_include_tag "application", :async => true

and it works for the javascripts. But is this isn't possible with the stylesheet_link_tag like:

stylesheet_link_tag "application, :media => "all", :async => true

also is this the "nice" way to do this? thanks

I'm using rails 3.2.12 and ruby 1.8.7

I want to load my javascripts and stylesheets async to have a better loading performance; with javascript I know I can load the javascripts async with:

javascript_include_tag "application", :async => true

and it works for the javascripts. But is this isn't possible with the stylesheet_link_tag like:

stylesheet_link_tag "application, :media => "all", :async => true

also is this the "nice" way to do this? thanks

I'm using rails 3.2.12 and ruby 1.8.7

Share Improve this question edited Feb 18, 2014 at 19:49 joseramonc asked Feb 12, 2014 at 20:11 joseramoncjoseramonc 1,9312 gold badges21 silver badges40 bronze badges 3
  • Ruby 1.8.7 reached End of Life some time ago - you should really look at upgrading. – sevenseacat Commented Feb 13, 2014 at 7:10
  • @sevenseacat any way to do it in ruby 1.9.2 or 2.0? – joseramonc Commented Feb 13, 2014 at 7:13
  • the problem is unrelated to the version of Ruby, I'm simply suggesting that you should really upgrade your app to a newer version. – sevenseacat Commented Feb 13, 2014 at 7:14
Add a ment  | 

1 Answer 1

Reset to default 8

The async attribute is not available on the <link> tag. It is only used for asynchronously downloading external script resources.

The idea is that you don't want to delay the CSS download because it is needed to render the page whereas javascript can often be downloaded at the same time as the html and executed when it has pleted.

It doesn't make sense for there to be an async option for external css resources.

发布评论

评论列表(0)

  1. 暂无评论