Referencing scripts from MVC Views
I am sure many have asked, but it is hard to search the forums since the new site launched.
I am familiar with how to register jQuery and other scripts in masterpages with the JavascriptEmbedControl and ResourceFileLink controls, but how does that process translate to when you are using MVC?
I have a view that I will be adding a slideshow player to and I want to load jQuery only if it has not been loaded already. I got it to load with the following in the view.
<
script
src
=
"@Url.Content("
//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js")"></
script
>
This is what I have ended up with so far and it works both on the frontend and backend without any script errors, but it feels too easy.
<
link
type
=
"text/css"
rel
=
"stylesheet"
href
=
"/Sitefinity/WebsiteTemplates/Public/App_Themes/Public/Styles/orbit.css"
/>
<
script
src
=
"@Url.Content("
//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js")"></
script
>
<
script
src
=
"@Url.Content("
/Sitefinity/WebsiteTemplates/Public/Scripts/foundation.js")"></
script
>
With ASP.MVC, it is *supposed* to be that easy. If it doesn't work, please update this thread as I'll be doing something like that soon as well.
You may wish to include a require.js type of script loader to check if the script exists on the page already so you don't duplicate the download, but that's not necessary if you know that there won't be any duplicate scripts on your page.