Problems upgrading from version 4.0.202.1 to recent release

Sep 24, 2012 at 5:13 PM
Edited Sep 24, 2012 at 5:14 PM

In de beginning of the development phase of our webapplication (.NET 4.0 programming in VB.Net), we started using the AjaxMin.dll version 4.0.202.1 to minify our JS and CSS files on the fly when serving them to the client. 
That always worked fine, without an explicit need to upgrade to a newer version.

Today a new customer complained that one of his modern CSS statements was minified wrongly, causing his webpages to be displayed incorrectly.

The CSS media statement:
"@media only screen and (min-width: 768px) {" 

is minimised to:
"@media onlyscreen and(min-width:768px){"

There are some crucial spaces missing there...

So we tried downloading and implementing the latest release of the AjaxMin.dll, but it didn't work out. Somehow then all of a sudden all minified CSS files are totally ignored by the browser.
We've also tried some other recent releases, but there's no difference.

So for the time being we're now back to version 4.0.202.1 and we've commented out the CSS minification entirely. But that's not the way we want it to be.

Can anyone maybe explain why all our CSS files are ignored by browsers when we minify them using a recent version of the AjaxMin.dll ?

Coordinator
Sep 24, 2012 at 5:46 PM

Wow -- 4.0 to 4.67 is a huge jump. I can say that recent versions do correctly maintain that significant space in CSS media queries, so that particular error should stop happening if we can get your other pro

Now, as for all minified files being totally ignored by the browser, I have no idea. Is there a sample source CSS file you can send me that works unminified and is ignored when minified under the latest version? Are there any errors thrown when you run the file through AjaxMin.exe? You're using the DLL to minify on the fly, right? What CodeSettings properties are you using?

Sep 26, 2012 at 8:48 AM
On second thought, I don't think the minified CSS files themselves are ignored... the .NET HttpHandler that handles requests for *.css files is ignored since we upgraded the AjaxMin.dll to the newest version.

Originally, we started using AjaxMin.dll based on this article: http://madskristensen.net/post/Performance-tuning-tricks-for-ASPNET-and-IIS-7-e28093-part-2.aspx
So we don't only use the DLL for minifying, we're also 'versioning' our CSS files.

Thus our CSS files are referenced in the HTML like this:
<link rel="stylesheet" href="/css/v_634840401772178042/styles.css" type="text/css" />

instead of like this:
<link rel="stylesheet" href="/css/styles.css" type="text/css" />
We need the CSS files to be run through our HttpHandler, to 'translate' that versioned href path back to the original one.
But the HttpHandler seems to be totally ignored when we upgrade to a recent AjaxMin.dll. And it is immediately respected again when we downgrade to the old AjaxMin.dll.


The old AjaxMin.dll we were using was compiled against .NET 2.0, whereas I understand the more recent ones are compiled against .NET 4.0.
Could it be that this is the cause of my problems after upgrading?

Best regards, Marja


On 24-9-2012 18:46, ronlo wrote:

From: ronlo

Wow -- 4.0 to 4.67 is a huge jump. I can say that recent versions do correctly maintain that significant space in CSS media queries, so that particular error should stop happening if we can get your other pro

Now, as for all minified files being totally ignored by the browser, I have no idea. Is there a sample source CSS file you can send me that works unminified and is ignored when minified under the latest version? Are there any errors thrown when you run the file through AjaxMin.exe? You're using the DLL to minify on the fly, right? What CodeSettings properties are you using?


Sep 26, 2012 at 11:40 AM
Could it be that the AjaxMin.dll intercepts CSS files (using some handler) and then, after processing it, sends it through to the browser with the wrong MIME type?

Because in Firefox I get errors like this:
Error: The stylesheet <mystylesheet>.css was not loaded because its MIME type, "text/html", is not "text/css".

while in the HTML source I definitely have:
<link rel="stylesheet" href="
<mystylesheet>.css" type="text/css">



Coordinator
Sep 26, 2012 at 4:03 PM

The AjaxMin dll knows nothing about mime-types -- it take a string as an input and outputs another string, so I don't think that's it. However, the http handler is interesting to me. Did you recompile the handler at all, or just swap out the AjaxMin.dll binary? Is there a log file you can look at on your serer to see if the handler is throwing any errors? I'll read Mads' article for any source code for his handler and see if I notice any changes in the way AjaxMin interacts.

Sep 26, 2012 at 4:07 PM
The handler is part of my application. So when it the application is
recompiled with a reference to the new AjaxMin.dll binary, the handler
is recompiled as well.
It really all works fine with the old AjaxMin.dll, but not with a more
recent one.
Coordinator
Sep 26, 2012 at 4:12 PM

Are you building to .net 2.0? You mentioned that earlier. I can send you a 2.0 build of the DLL if you want to try that. I've read Mads' blog and downloaded the code; running through it myself to see where it breaks.

Coordinator
Sep 26, 2012 at 4:15 PM

(Just an update) Nothing's changed in the AjaxMin interface he's calling; it should work fine. I'll start creating an ASP.NET application, get it working with the ancient DLL he provided, then update the DLL and see what happens.

Sep 26, 2012 at 4:17 PM
No, I'm building to .Net 4.0.

I think the MIME type thing results from the HttpHandler being ignored
after implementing the new AjaxMin.dll.
Because then the 'versioned' paths to the CSS files result in 404 error
pages. And those are MIME type html of course.

So I need to figure out why the handler is ignored when the new
AjaxMin.dll is used.

Thanks for looking into this issue!
Coordinator
Sep 26, 2012 at 7:55 PM
Edited Sep 26, 2012 at 7:58 PM

Well, crud. So I created a new ASP.NET web app in VS2010, I added FileBundleHandle.cs (very cool code) to the project, added a reference to the 4.0 verison of the DLL he had, created a folder with JS and CSS files in it, then added the calls to BundleHelper.InsertFile to the Default.ASPX page for the bundled JS and CSS folders. I needed to add the handler references to web.config in a slightly different manner than his instructions, though. Needed to be within a <handlers> container under <system.webServer>:

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
      <handlers>
          <add name="ScriptBundler" verb="GET,HEAD" path="*.js" type="FileBundleHandler" />
          <add name="CssBundler" verb="GET,HEAD" path="*.css" type="FileBundleHandler" />
      </handlers>
  </system.webServer> 

And it worked with the old DLL. So then I deleted the reference to the old AjaxMin.dll and added a reference to the new one, rebuilt, and... it still worked. No errors; CSS and JS both bundled, minified, downloaded, and ran properly. I made sure that the new code was running by using stuff I knew would minify differently in the old and new versions, including the media query from your original post.

I checked which version of AjaxMin I had installed on my machine and I was still on 4.66. So I installed 4.67 from the website, rebuilt, ran again... and it failed! (Thank goodness -- I hate no-repro situations.) Okay. So I had HttpWatch running and hit the page again. The bundled files were failing with a 500 error, and this was in the output:

<title>Could not load file or assembly 'AjaxMin, Version=4.66.4632.31882, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)</title>

A-ha! It was still looking for the previous version! I didn't remove the reference and add the new one when I upgraded from 4.66 to 4.67! Once I did that (delete reference/add new reference), the app started working again. So that's my guess for what's happening with you: once you update the AjaxMin.dll to the latest version, can you delete the reference from your project and add it again? I think that will clear up the issue.

Oct 5, 2012 at 11:08 AM
Hi ronlo,

Just to let you know I haven't abandoned this thread:
I haven't had the time yet to test this again. Will let you know as soon as I have some more information.

Thank you for your time and efforts so far!

Best regards, Marja


On 26-9-2012 20:55, ronlo wrote:

From: ronlo

Well, crud. So I created a new ASP.NET web app in VS2010, I added FileBundleHandle.cs (very cool code) to the project, added a reference to the 4.0 verison of the DLL he had, created a folder with JS and CSS files in it, then added the calls to BundleHelper.InsertFile to the Default.ASPX page for the bundled JS and CSS folders. I needed to add the handler references to web.config in a slightly different manner than his instructions, though. Needed to be within a <handlers> container under <system.webServer>:

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<add name="ScriptBundler" verb="GET,HEAD" path="*.js" type="FileBundleHandler" />
<add name="CssBundler" verb="GET,HEAD" path="*.css" type="FileBundleHandler" />
</handlers>
</system.webServer>

And it worked with the old DLL. So then I deleted the reference to the old AjaxMin.dll and added a reference to the new one, rebuilt, and... it still worked. No errors; CSS and JS both bundled, minified, downloaded, and ran properly. I made sure that the new code was running by using stuff I knew would minify differently in the old and new versions, including the media query from your original post.

So I checked which one I had installed and I was still on 4.66. So I installed 4.67 from the website, rebuilt, ran again... and it failed! (Thank goodness -- I hate no-repro situations.) Okay. So I had HttpWatch running and hit the page again. The bundled files were failing with a 500 error, and this was in the output:

<title>Could not load file or assembly 'AjaxMin, Version=4.66.4632.31882, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)</title>

Aha! It was still looking for the previous version! I didn't remove the reference and add the new one! Once I did that, it started working again. So that's my guess for what's happening with you: once you update the AjaxMin.dll to the latest version, can you delete the reference from your project and add it again? I think that will clear up the issue.