This is a migrated thread and some comments may be shown as answers.

[Solved] ScriptRegistrar order while using AssetHandler

9 Answers 127 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kelly Stuard
Top achievements
Rank 1
Kelly Stuard asked on 04 Feb 2010, 08:58 PM
Given the following:
.Add("file1.js")  
.Add("file2.js")  
.Add("directory/otherfile.js")  
.Add("file3.js") 
The script render out in that order when the page is loaded normally. This is expected.

If i add '.Combined(true)' then suddenly they are rendered as one reference (expected). However, the single file that is output is in the wrong order. Any files without a subdirectory are rendered first, before the ones in a directory. This is killing me for script-dependency reasons.

Actual order when combined (unexpected):
file1.js  
file2.js  
file3.js  
directory/otherfile.js 

9 Answers, 1 is accepted

Sort by
0
Kelly Stuard
Top achievements
Rank 1
answered on 05 Feb 2010, 10:07 PM
Upgraded to version 2009.3.1320. Still an issue.
0
Anthony Smith
Top achievements
Rank 1
answered on 07 Feb 2010, 11:15 PM
I posted about a little while ago and also being able specify order, etc but at the time they said that they would put it on the wish list.
0
Kelly Stuard
Top achievements
Rank 1
answered on 07 Feb 2010, 11:21 PM
But we are specifying the order by the order we call .Add. There is no reason to add any additional functionality to the order. I'm just asking for the order with and without .Combined to be the same.
0
Kelly Stuard
Top achievements
Rank 1
answered on 08 Feb 2010, 12:01 AM
A little clarification, I guess. This actually presents a substantial problem, due to the way we use .js files (and I suppose .css files behave the same way).

Our adds go as follows:
.Add("library/jquery.js")  
.Add("library/ajax.js")  
.Add("library/other-3rd-party.js")  
 
.Add("our-stuff.js")  
.Add("our-pagelevel.js") 

Without .Combined() the scripts go out in the correct order (the order they were added). For whatever reason (I haven't been able to look through the asset handler to figure it out), it's rendering out in a different order (with the ones in the library directory last). As you can imagine, having the library scripts not loaded when our scripts do their thing causes massive JavaScript errors.

I'm just asking for consistancy between the methods of outputting scripts. It's very painful to have different behavior between development and release. Makes it harder to track down bugs.
0
Accepted
Kazi Manzur Rashid
Telerik team
answered on 08 Feb 2010, 07:19 PM
Hello Kelly Stuard,

This issue has been fixed and it will be available in our next drop.

Thanks for reporting the issue.

All the best,
Kazi Manzur Rashid
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Kelly Stuard
Top achievements
Rank 1
answered on 10 Feb 2010, 04:15 PM
Do you know when the next drop will be available? I see nothing under the "Latest Internal Builds" section and the latest release is BETA 2009.3.1320 (Jan 20, 2010).
0
Atanas Korchev
Telerik team
answered on 10 Feb 2010, 05:01 PM
Hello Kelly Stuard,

We have not decided yet when to publish a new build. If this is a showstopper for you let me know so I can paste the code required to fix the bug.

Regards,
Atanas Korchev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Kelly Stuard
Top achievements
Rank 1
answered on 10 Feb 2010, 05:03 PM
If there's not going to be a drop in the next 10 days, I would greatly appreciate the code. This is not an issue in our dev environment; but, once we push to QA it will be expected for the files to be combined [correctly].

[Edit] Oh, and thanks to your team for the quick resolution of this issue.
0
Atanas Korchev
Telerik team
answered on 11 Feb 2010, 08:10 AM
Hello Kelly Stuard,

In WebAssetRegistry.cs replace this code:

foreach (MergedAssetDirectory directoy in asset.Directories)
{
    foreach (MergedAssetFile file in directoy.Files.OrderBy(f => f.Order))
    {
        string path = "~/" + directoy.Path + "/" + file.Name;
 
        string virtualPath = assetLocator.Locate(path, asset.Version);
        string fileContent = virtualPathProvider.ReadAllText(virtualPath);
 
        if (string.Compare(asset.ContentType, "text/css", StringComparison.OrdinalIgnoreCase) == 0)
        {
            string baseDiretory = virtualPathProvider.GetDirectory(virtualPath);
             
            fileContent = ReplaceImagePath(baseDiretory, asset.Version, fileContent);
        }
 
        contentBuilder.AppendLine(fileContent);
 
        physicalPaths.Add(pathResolver.Resolve(virtualPath));
    }
}

with this code:

var files = asset.Directories
             .SelectMany(d => d.Files.Select(f => new { Directory = d, File = f }))
             .OrderBy(f => f.File.Order);
 
foreach (var pair in files)
{
    string path = "~/" + pair.Directory.Path + "/" + pair.File.Name;
 
    string virtualPath = assetLocator.Locate(path, asset.Version);
    string fileContent = virtualPathProvider.ReadAllText(virtualPath);
 
    if (string.Compare(asset.ContentType, "text/css", StringComparison.OrdinalIgnoreCase) == 0)
    {
        string baseDiretory = virtualPathProvider.GetDirectory(virtualPath);
 
        fileContent = ReplaceImagePath(baseDiretory, asset.Version, fileContent);
    }
    contentBuilder.AppendLine(fileContent);
    physicalPaths.Add(pathResolver.Resolve(virtualPath));
}

Greetings,
Atanas Korchev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
General Discussions
Asked by
Kelly Stuard
Top achievements
Rank 1
Answers by
Kelly Stuard
Top achievements
Rank 1
Anthony Smith
Top achievements
Rank 1
Kazi Manzur Rashid
Telerik team
Atanas Korchev
Telerik team
Share this question
or