I'm attempting to develop a time picker data type, but I'm running into an issue with conflicting javascript dependencies. I thought I could try to use Client Dependency to overcome that, however, I've been unsuccessful at getting that to work... at all. So I thought I'd take a look at the uComponents source to see how its being done there because as far as I know, uComponents uses CD.
But looking at the source, it appears that uComponents injects the resource dependencies directly into the head of the html document and doesn't use CD at all... Am I reading this wrong?
You are right, we don't (currently) use ClientDependency in uComponents. The reason behind this was a bug with CD that didn't allow you to register embedded resources (which is how we deliver all CSS/JavaScript in uComponents).
I believe this bug has been fixed in CD, but since that we still support Umbraco v4.5.2, the version of CD that shipped with it still has the bug. Hence why we inject the script tags directly into the <head>.
With the next major release of uComponents (v4.0), we'll be raising the support to Umbraco v4.7+, so hopefully we can use CD.
If you want to see an example of a package using CD, take a look at this code in the source of the Google Maps package.
Thanks for your reply. I thought I was going crazy yesterday. Thanks for the source code for the Google Maps package. I copied and pasted the code into my project, but it doesn't appear to be adding it to CD. Any thoughts as to what I'm missing?
using System; using System.Web.UI; using ClientDependency.Core; using ClientDependency.Core.Controls; using umbraco;
namespace CoB.Umb.DataTypes.TimePicker { public static class TimePickerExtensions { public static void AddResourceToClientDependency(this Control ctl, string resourceName, ClientDependencyType type) { ctl.Page.AddResourceToClientDependency(typeof(TimePickerExtensions), resourceName, type, 100); }
public static void AddResourceToClientDependency(this Page page, Type resourceContainer, string resourceName, ClientDependencyType type, int priority) { // get the urls for the embedded resources var resourceUrl = page.ClientScript.GetWebResourceUrl(resourceContainer, resourceName); ClientDependencyLoader.Instance.RegisterDependency(priority, page.Server.HtmlEncode(resourceUrl), type); } } }
using ClientDependency.Core; using ClientDependency.Core.Controls;
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.UI; using System.Web.UI.WebControls;
Indeed, I have... Oh well, I'll just use ScriptManager for now I guess. It doesn't give me the compression, but atleast it gets them there. This is what I'm doing for now, until I figure out what I'm doing wrong:
I had issues using ScriptManager to register my resources the other day. What I found was that for some reason I had to use typeof(CurrentClassName) instead of this.GetType():
I wasn't aware of it, but I guess there's a difference between typeof and GetType, one is the type at compile time, the other is the type at runtime: Type Checking: typeof, GetType, or is?
uComponents doesn't use Client Dependency?
I'm attempting to develop a time picker data type, but I'm running into an issue with conflicting javascript dependencies. I thought I could try to use Client Dependency to overcome that, however, I've been unsuccessful at getting that to work... at all. So I thought I'd take a look at the uComponents source to see how its being done there because as far as I know, uComponents uses CD.
But looking at the source, it appears that uComponents injects the resource dependencies directly into the head of the html document and doesn't use CD at all... Am I reading this wrong?
Hi Douglas,
You are right, we don't (currently) use ClientDependency in uComponents. The reason behind this was a bug with CD that didn't allow you to register embedded resources (which is how we deliver all CSS/JavaScript in uComponents).
I believe this bug has been fixed in CD, but since that we still support Umbraco v4.5.2, the version of CD that shipped with it still has the bug. Hence why we inject the script tags directly into the <head>.
With the next major release of uComponents (v4.0), we'll be raising the support to Umbraco v4.7+, so hopefully we can use CD.
If you want to see an example of a package using CD, take a look at this code in the source of the Google Maps package.
Cheers, Lee.
Hi Lee,
Thanks for your reply. I thought I was going crazy yesterday. Thanks for the source code for the Google Maps package. I copied and pasted the code into my project, but it doesn't appear to be adding it to CD. Any thoughts as to what I'm missing?
Sorry, I have to ask the obvious question... have you set the CSS/JS files to be "Embedded Resource" in the properties (in Visual Studio)?
The rest of the code looks like it should work.
Cheers, Lee.
Indeed, I have... Oh well, I'll just use ScriptManager for now I guess. It doesn't give me the compression, but atleast it gets them there. This is what I'm doing for now, until I figure out what I'm doing wrong:
I had issues using ScriptManager to register my resources the other day. What I found was that for some reason I had to use typeof(CurrentClassName) instead of this.GetType():
I wasn't aware of it, but I guess there's a difference between typeof and GetType, one is the type at compile time, the other is the type at runtime: Type Checking: typeof, GetType, or is?
is working on a reply...