I am reading a book for "Ruby on Rails". In the "application.js", we are including other JavaScript libraries in the following way and more specific - jQuery UI:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
As this is ordinary JavaScript file (not ruby extensions here like "html.erb" for exmaple) how the application knows to execute the require mand? What kind of JavaScript syntax is this:
//=
and as this is ordinary JavaScript file, why we are not using "script" tags to include JavaScript files?
Also, I have read here that "require" method will check for this library in define by $LOAD_PATH variable folders. How can I see where the "jquery-ui" is stored? I am asking because in other applications in order to use jQuery UI I should add not only JavaScript file, but css file and images used by the library - in this case, we are doing this only with single line?
I am reading a book for "Ruby on Rails". In the "application.js", we are including other JavaScript libraries in the following way and more specific - jQuery UI:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
As this is ordinary JavaScript file (not ruby extensions here like "html.erb" for exmaple) how the application knows to execute the require mand? What kind of JavaScript syntax is this:
//=
and as this is ordinary JavaScript file, why we are not using "script" tags to include JavaScript files?
Also, I have read here that "require" method will check for this library in define by $LOAD_PATH variable folders. How can I see where the "jquery-ui" is stored? I am asking because in other applications in order to use jQuery UI I should add not only JavaScript file, but css file and images used by the library - in this case, we are doing this only with single line?
Share Improve this question asked Nov 4, 2012 at 11:09 gotqngotqn 43.7k46 gold badges165 silver badges254 bronze badges 01 Answer
Reset to default 10What kind of JavaScript syntax is this.
Anything starting with a //
is a Javascript ment.
How is it able to process it ?
Sprockets on the server side scans the JS file for directives
. //=
is a special Sprocket directive. When it encounters that directive it asks the Directive Processor to process the mand, require
in this example. In the absence of Sprockets the //= require ..
line would be a simple JS ment.
Ruby require
vs Sprockets require
These are two pletely different things. The one you link to is Ruby's require.
Why not use script tags to load JS files.
Usually, you want to concatenate all your app JS files and then minify them into 1 master JS file and then include that. I remend reading the YSlow best practices on this.
I also remend watching the Railscasts on Asset Pipline - http://railscasts./episodes/279-understanding-the-asset-pipeline
Cheers!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744388605a4571792.html
评论列表(0条)