Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

ruby - Rails 3.1 Pipeline - Exclude Javascript File

I want to exclude a particular javascript file (modernizr) from the pipeline because I want it to load separately.

I want to load Modernizr at the beginning and the rest of my javascript concatenated at the end.

Is there way to do the opposite of a require in the asset pipeline in 3.1? ie. an exclude?

Thanks in advance.

Adam.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I chose to keep the sprockets functionality by changing

//= require_tree

to

//= require_directory .

This keeps sprockets auto-loading any files in the same directory, but not in any folders further.

This allowed me to move Modernizr.js to the assets/javascripts/top folder and manually load it at the top with:

<%= javascript_include_tag "top/modernizr" %>

and move

<%= javascript_include_tag "application" %>

To the bottom of my application.html.erb file (above the closing body tag)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...