How to reference external scripts.

93 views
Skip to first unread message

John Welborn

unread,
Dec 29, 2011, 4:36:14 PM12/29/11
to Cassette
How do I define a reference to an external script?

For example, if I'm using jquery as an external reference on a cdn,
how do I reference that script for a plugin?

Sort of related to this and a previous question... do I need to edit
every plugin I download to add a reference to jquery? This seems
wrong.

Andrew Davey

unread,
Jan 3, 2012, 8:58:56 AM1/3/12
to cass...@googlegroups.com
Changing a third-party script is something to avoid if possible! There are other ways to define a bundle's references.

Option 1) If using a bundle.txt file, try adding a [references] section:


third-party-widget.js
some-plugin.js

[references]
~/jquery

This assumes that "jquery" is an alias for the CDN URL. i.e.
bundles.AddUrlWithAlias("http://cdn.com/jquery.js", "jquery");

(You can just put the URL into the bundle.txt, but that'll make updating versions more work later.)
---

Option 2) Call Bundle.AddReference

In CassetteConfiguration, try this:
bundles.Add<ScriptBundle>("path", b => b.AddReference("jquery"));

Or after the Add* calls, you can get to the bundle by its path:
bundles["path"].AddReference("jquery");
---

If you do own the script file, then reference either the jquery CDN URL, or the alias:
/// <reference path="~/jquery"/>

I hope that helps. Please let me know if you have more questions.

Thanks,
Andrew

John Welborn

unread,
Jan 4, 2012, 11:40:37 AM1/4/12
to Cassette
Awesome! That's exactly what I needed to know!
Reply all
Reply to author
Forward
0 new messages