1
Vote

Duplicate path in groups excludes file

description

Hi we are using assman and have found an issue when you have the same file referenced in two groups.

Example below:
Home.js includes the jquery.cycle.lite.js but the TagTopic.js does not. Home.js and TagTopic.js are not used on the same page. I have attached the rest of our config for your reference.

<group consolidatedUrl="~/Scripts/Consolidated/Home.js" minify="ReleaseOnly">
    <include>
      <add path="~/Scripts/Libraries/jquery.cycle.lite.js" />
      <add regex="~/Views/Home/_.+" />
    </include>
  </group>
  <group consolidatedUrl="~/Scripts/Consolidated/TagTopic.js" minify="ReleaseOnly">
    <include>
      <add path="~/Scripts/Libraries/jquery.cycle.lite.js" />
      <add path="~/Scripts/Libraries/json2.js" />
      <add regex="~/Views/Tag/_.+" />
      <add regex="~/Views/Topic/_.+" />
      <add regex="~/Views/Shared/VideoWall/_.+" />
    </include>
  </group>
Any help with this would be greatly appreciated.

file attachments

comments

andyalm wrote Dec 20, 2011 at 6:16 PM

This behavior is currently working as designed. Currently, an individual .js file is only allowed to be part of one group. There are a couple reasons for this. There are pros and cons to allowing files to be in multiple groups. If you allow them, then you essentially start creating groups that are targeted to individual pages (or sets of pages). The benefit of this is that each individual page can start including only what it needs, which will make each page as lean as possible. However, the con to that approach is that you don't end up leveraging your browser cache as much as you could. In addition, you have to make sure that you don't include two groups on the same page that have overlapping scripts in them. That last part is the scary part to me, as a good part of that complexity would need to be handled by Assman. One of Assman's most important features (in my opinion) is its dependency management. It uses the ///<reference> entries at the top of your .js files to order your .js files within a group and to make sure that if you request a script to be on your page, that all dependencies are included first. Since ///<reference> entries typically reference individual files (rather than groups), Assman has to do a lookup to map the individual .js file to its group. If a .js file can be in multiple groups, then it wouldn't know which group to map it to. All that is to say, if we start to allow scripts to be in multiple groups, then dependency management becomes much harder.

I'm still thinking through these issues and trying to figure out a way that I could enable this behavior. If you don't care about the dependency management piece and are fine managing dependencies on your own, then it wouldn't be a problem to enable this. I could put in an undocumented hook for you if you would like. Let me know.

richhalliwell wrote Jul 4, 2012 at 3:49 PM

Hi sorry for the very very late reply.

First off can I say that we have been using Assman on our high traffic, high development website for over a year now and it has been a premium dev tool when it comes to managing multiple js and css files.

Lately we have been optimising the page load of the site with fewer http requests. Groups like above have helped us with this. As we add more functionality this issue is becoming more of a problem as we want to share certain files across groups.

We have setup our groups by page (essentially we have 3 high traffic pages) to ensure page load time is at a minimum.

We have discussed this topic internally here many times and the best solution we have come to is if we could assign each of our 3 pages with its respective consolidated js group. Assman would include that group file and then check for any separate files included on the page that are not within the group and include separately. We would aim to have our groups outlined in assman to reduce the separate files being included but it is a good way to see if we have missed a file in the group without the site breaking.

I think this solution would get around the problem of assman not knowing what group to include when a file is shared across groups.

I'm not sure of the difficulty of this fix but we would be interested in your feedback.

Thanks

andyalm wrote Jul 5, 2012 at 6:01 AM

Hey Rich,

Thanks so much for the feedback. I'm heading out on vacation tomorrow, so I don't really have time to respond thoroughly. I think all of your reasoning makes sense and I would like to work with you to find an easy fix for this problem. When I first wrote Assman, I did not think including files in more than one group was a good idea, but I have sense come to see that there are valid use cases for it. As long as you include your files on the page by referring to the group path rather than individual file paths, there should not be a problem with allowing individual files to be part of multiple groups. We simply need to modify Assman to allow it.

A big technical reason that Assman currently prevents files from being in multiple groups is because Assman allows you to require individual files from your view. If an individual file can be part of more than one group, Assman would have no idea which group needs to be included on that page.

I think for the short term, I should be able to add a config flag that allows files to be part of more than one group. I believe it should be a very small amount of work. I will try to get to it when I get back from vacation (at the end of next week). I apologize I won't be able to get anything out there sooner. Feel free to dive into the code and if you figure out how to do this yourself, I'll accept a pull request :-)

~Andy

richhalliwell wrote Jul 5, 2012 at 8:48 AM

Thanks Andy, we will wait for your return and implement your change.

Enjoy your vacation.

andyalm wrote Jul 12, 2012 at 4:41 AM

Hi Rich,

I have published a beta version of the Assman.Core NuGet package which contains the functionality you requested. The beta package is version "2.0.9-beta". Note that NuGet sees this as a prerelease package. Because this change would be a major breaking change to be enabled by default, I have added a new config setting that you will need to set to get the desired functionality. To allow individual files to be part of more than one group, add this attribute to your <assman> element in your Assman.config file:

<assman mutuallyExclusiveGroups="false">

Please try this out and let me know how it works. If it works well for you, I will publish a final release for 2.0.9 so that everyone can upgrade to it.

~Andy

jamiegardyne wrote Jul 12, 2012 at 2:51 PM

Hi Andy

My name is Jamie and I have been tasked with upgrading Assman.

I have updated the dll file and updated our config with the mutuallyExclusiveGroups attribute, but are not seeing changes.

Is there anything else we need to change? I have tried adding the group reference to each page so assman knows what group to use.

If you look at our updated config attached we have files shared between the TagTopic.js & VideoContentLayout.js

When on a page that uses TagTopic the script works and TagTopic is included. When on a page that uses VideoContentLayout.js we find TagTopic.js is included also.

This is the same issue we had before the upgrade which led me to believe that I hadn't updated the dll properly. I rolled back the assman dll and added the mutuallyExclusiveGroup attribute to the config which caused an error. I then updated the dll and the error disappeared.

Thanks
Jamie

andyalm wrote Jul 12, 2012 at 8:17 PM

Hi Jamie,

Thanks for the detailed explanation. I'm guessing what is happening is that somewhere in one of your views you are requiring an individual file that is in the TagTopic.js group. When that is happening, Assman is doing a lookup of that file and seeing that it matches TagTopic and it is adding it to the page. If that file is also in the VideoContentLayout.js file, Assman currently does not notice, even if you have already required the VideoContentLayout.js file on the page. Assman currently just isn't quite smart enough. When I added the mutuallyExclusiveGroups flag, I was under the impression that you guys were only requiring files by their group url and not requiring individual files. Requiring individual files is what makes having overlapping groups complicated, which is why it has not been supported :-).

Here is what I think we can do to fix this.
  1. I believe it should be doable to make Assman a little smarter here so that if it notices that VideoContentLayout.js has already been required on the page, then when you require an individual file that is in both VideoContentLayout.js and TagTopic.js, it will notice that it is part of both groups, and since one of those groups is already included, then it does not need to require TagTopic.js. Right now, it chooses the first match regardless of what has already been required, and since TagTopic.js appears in the Assman.config first, it always wins. This work will take me a few days to complete.
  2. If you don't want to wait for a fix, then the other option you have is to stop requiring individual files (at least ones that are in multiple groups) and instead just require the group url's directly instead. If you do that, then things should work as you want.
Does that all make sense? Feel free to contact me directly (either email or chat) via "andyalm at gmail dot com".

~Andy

andyalm wrote Jul 16, 2012 at 4:44 AM

So I spent some time over the weekend looking into this issue more, and unfortunately the code that deals with including the correct scripts on the page has assumptions baked in that any given script can be part of only one group, so it is taking a bit more work to fully support your scenario than I originally thought. It was very easy to let multiple groups include the same file, but updating the .Require to do the right thing in that scenario is going to take some more work. We're probably looking at a week or two of work for me to get this fully working. I apologize for the delay. I will keep you updated on my progress.

jamiegardyne wrote Jul 16, 2012 at 8:45 AM

No problem Andy, thanks for the help with this.

andyalm wrote Jul 17, 2012 at 4:57 AM

Hi Jamie,

I was actually able to make good progress on this today and I have something that would be worth trying out. I have published a new Assman.Core package on NuGet (version 2.1.0-alpha). When you get a chance, please pull it down and try it out. It contains a rewrite of the algorithim that is used to decide what assets to include on the page and where. I believe it should work the way you are expecting now. Please try it out and let me know how it goes. I want to do some additional testing of this code before it goes live, but your feedback would be greatly appreciated.

~Andy

jamiegardyne wrote Jul 17, 2012 at 8:49 AM

Hi Andy,

I have updated to 2.1.0-alpha and my findings are below.

Pages using Tagtopic are working fine.

The only problem I can see is assman isn't respecting the registry name. When using "head" assman places code correctly in the head. We have another registry name called "jquery_head" and have found the consolidated file being placed in the head (correct) and duplicated in the footer.

I could look at uploading a staging version of assman if you need to see an example.

Cheers
Jamie

andyalm wrote Jul 17, 2012 at 1:39 PM

Hi Jamie,

Thanks for the update. An example of your Assman.config as well as your RequireScript calls on the page that isn't working would be very helpful.

jamiegardyne wrote Jul 17, 2012 at 2:28 PM

Hi Andy,

Our config hasn't changed from the latest uploaded to this thread apart from the comments in tagtopic and videoContentLayout being uncommented.

Listing all of the require scripts is going to be time consuming as there are a lot of partials within our problem page.

I will organise a staging address and email your private email with the address.