Documentation

External Scripts

You may want to reference an external script URL in multiple pages. Repeating the URL in each page is not ideal. If you ever need to change it you'll have to search through all the pages.

Cassette supports the definition of external script URLs at the application level. You can then reference them by a short, fixed, name. In addition you can specify a fallback URL if, for example, a CDN fails.

public class CassetteConfiguration : ICassetteConfiguration
{
    public void Configure(BundleCollection bundles, CassetteSettings settings)
    {
        bundles.AddUrlWithAlias(
            "http://platform.twitter.com/widgets.js",
            "twitter"
        );

        bundles.AddUrlWithLocalAssets(
            "//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js",
            new LocalAssetSettings
            {
                // Local assets for use in debug mode.
                Path = "scripts/jquery.js",
                // When condition is true, uses the local assets
                FallbackCondition = "!window.jQuery"
            }
        );
    }
}

Now in view pages, these external scripts can be referenced by path.

@{
  Bundles.Reference("scripts/jquery.js");
  Bundles.Reference("twitter");
}
<!DOCTYPE html>
<html>
...