2

I have a coffee script user.js.coffee, that is only used in certain views. I achieved this by using the following answer:

https://stackoverflow.com/a/6795533/784318

Now I have excluded the script from the application.js. I also removed the //= require_tree . entry.

So my file is available here: http://localhost:3000/assets/user.js however, when I deploy this to the server the assets will be combined in one application.js so how can I make sure that the user.js will be available on production like so: http://myserver.com/assets/user.js?

2 Answers 2

2

In environments/production.rb (or the environment you need precompile to occur) uncomment or add this file to the precompile array:

# environments/production.rb

config.assets.precompile += %w( user.js )

Other entries might be already present, just add any other file that you need to access separately.

This file will not get compiled in one big application.js file and will be accessible separately as user.js

Sign up to request clarification or add additional context in comments.

7 Comments

This looks promising. I will test that out on production. Do you know if I have to use user.js.coffee in my case?
user.js should work fine. At least it works in my case. It should pickup the .coffee by itself
@Oktav but the compiled file will have the name with fingerprint like user-e55bd5e3eb82fa4e8034af2883dc37e8.js so we can't definitely know the path to it.
@freemanoid You need to include that file via javascript_include_tag "user" in your view and it should include the file with the correct fingerprint. Also the fingerprint will change only if the content of the js file changes.
@Oktav but what if I need to post the link to this file on 3rd party resource? I need to know the link to do that.
|
0

You can try putting your user.js file to the public folder of your application directly and configure your asset pipeline to exclude it from the "zipping" process.

2 Comments

Well it is not a .js file but a .js.coffee file. So it will at least have to processed by the coffee-script compiler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.