简体   繁体   中英

Inline Javascript in Rails

I've been just adding my individual scripts at the bottom of my rails views via script tags.

It just seems way easier and more intuitive to include a one off script in the actual view rather than a separate JS file. But what are the arguments against doing this?

Having the script in a separate file, you can:

  1. Include it in as many pages you want
  2. Have it pre-processed and minified in production
  3. Declare depedencies between modules
  4. Lint it using tools like jshint
  5. Test it, having one test file per source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM