1

I found a library called Xpedite. the URL of the project is http://xpedite.codeplex.com. From here anyone can download the project with a sample. I checked this library and it is good.

The user only needs to wrap up the js file name with page like this:

<xpedite:CompositeResourcePlaceholder runat="server" />

<xpedite:CompositeResource runat="server" Type="Css" ReferenceName="jquery-ui">
  <xpedite:Resource Url="/Styles/Site.css" />
  <xpedite:Resource Url="/Styles/jquery.ui.accordion.css" />
  <xpedite:Resource Url="/Styles/jquery.ui.all.css" />
</xpedite:CompositeResource>

<xpedite:CompositeResource runat="server" Type="JavaScript" ReferenceName="jquery-ui">
  <xpedite:Resource Url="/Scripts/jquery-1.4.2.js" />
  <xpedite:Resource Url="/Scripts/jquery.ui.core.js" />
  <xpedite:Resource Url="/Scripts/jquery.ui.tabs.js" />
</xpedite:CompositeResource>

Everything is working fine but I always have to define JS & CSS file in .aspx page level. Maybe sometimes I would like to add my JS & CSS from code-behind. I found no way to do it, so if anyone know it then please share the knowledge with me or download the project and check...I checked it but found nothing.

I am not an advanced developer but I need to wrap up the JS file in CompositeResource from code behind.

3 Answers 3

3

You might give the RequestReduce library a try. This library offers the same functionality as Xpedite and will minify and combine your css and javascript files. It can also sprite your css background images. With RequestReduce, it does not matter if your resources are defined on the aspx or the codebehind. Either way, as long as html that is streamed to the browser contains link and script tags with the javascript and css files, RequestReduce will process them.

Sign up to request clarification or add additional context in comments.

Comments

2

Have you tried using .Net's ClientDependencyFramework instead? It does a similar job I believe, but also lets you register files from code-behind

Comments

0

Adding answer for informational purposes:

To register a composite resource from the CodeBehind, you can add a new instance of the CompositeResource control in the Page_Init as follows:

CodeBehind

protected void Page_Init(Object sender, EventArgs e)
{
  var resource = new CompositeResource { Type = ResourceType.Css, ReferenceName = "CodeBehind"};

  resource.Resources.Add(new Resource { Url = "/Styles/Site.css"});
  resource.Resources.Add(new Resource { Url = "/Styles/jquery.ui.accordion.css"});

  Page.Controls.Add(resource);
}

Alternatively, you may choose to extend an existing CompositeResource if that resource has been given an ID:

ASPX

<xpedite:CompositeResource runat="server" Type="Css" ReferenceName="jquery-ui" ID="MyCompositeResource">

CodeBehind

protected void Page_Init(Object sender, EventArgs e)
{
  MyCompositeResource.Resources.Add(new Resource { Url = "/Styles/jquery.ui.theme.css" });
}

If you are dynamically generating CSS/JavaScript on the fly and trying to included it in a composite resource, that feature is currently not supported. Adding support for an 'EmeddedResource' would be relatively easy though if an issue is opened on the CodePlex project (although I plan on moving it to GitHub in the near future).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.