Rails 5 assets not mentioned on the `applications.js` manifest are served?

684 views Asked by At

Please enlighten me!

Let say I have the following assets structure in a Rails 5 application.

app/assets/javascripts
  application.js
  file1.js

In the application.js manifest I am not requiring //= file1 neither I am using require_tree . directive.

If a JS file is not required in any way in the manifest application.js neither is it included in the Rails.application.config.assets.precompile += %w[]

  1. Is this asset going to be served?
  2. If there is a tag in some view <%= javascript_include_tag 'file1' %> , should it work or raise an error?
1

There are 1 answers

0
stwienert On BEST ANSWER

No, that file is not served by default. By default (depending on Rails version/asset config), only the files listed in Rails.application.config.assets.precompile, by default application.js application.css or in newer Sprockets/Rails via files listed in manifest.js are available for direct serving via javascript_include_tag.

That 2. would raise an error.