Adding javascript and stylesheet files to the media library isn’t very useful unless they can be associated with specific content items. The follow steps show how easy it is to add two scripts a and stylesheet to the layout for the home page so that the title blinks and the background is blue.
We begin by seeing that a new template called MediaResource has been added to the User Defined templates.
Next we need to add the MediaResource template to the Sample Item template.
Now on the Home item, which inherits from the Sample Item template, we associate the new uploaded files.
Next we open up the layout and add the following markup as seen in the screenshot below:
Source Code |
---|
<%@ Register tagPrefix="ce" assembly="Sitecore.SharedSource.CodeEditor" namespace="Sitecore.SharedSource.Web.UI.WebControls" %> <ce:ResourceWebControl ID="ResourceWebControl1" runat="server" ResourceType="Style" Cacheable="true"> </ce:ResourceWebControl> <ce:ResourceWebControl ID="ResourceWebControl2" runat="server" ResourceType="Script" Cacheable="true"> </ce:ResourceWebControl> |
The results are amazing!
Blink.
Blink.
Finally, the proof that the resource were injected into the page.
The resources will be minified while compilation settings in the web.config are set to debug="false”.