user171110
user171110

Reputation:

sprockets: can I have two different javascript files included in two different controllers

I am working on a ruby on rails application. All the controllers have one javascript file. However there is a functionality ( call it business.js) which is needed by two controllers. Now just because two controllers need it , I don't want to put this logic in application.js which will make this logic available to all the controllers.

I want pages to have only the javascript files they must need and nothing extra.

I was wondering if sprockets is flexible enough to meet my requirement. From the documentation of sprocket I could not get any definite answer.

Upvotes: 1

Views: 306

Answers (1)

jonnii
jonnii

Reputation: 28322

Sprockets can do what you want. However I would think very carefully about what you are trying to do.

Where does the requirement come from that each page must have only the javascript it requires? If you were to put all your .js into file it would only be requested once and then cached on the client.

Upvotes: 2

Related Questions