• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 723
  • Last Modified:

vb.net: Compress js and css files to improve webpage loading times

Hi, I just want to compress my css and javascript files when they are sent to the client. Looking on the internet I can see lots of stuff in c# but just haven't been able to easily see how to do this in vb.net or even what way i should go about it (seems to be some people are putting code into the global.asax file or others using php or something... not sure)

How can I gzip (or deflate) my js and css files in vb.net. I'm using IIS7.
0
AidenA
Asked:
AidenA
  • 5
  • 3
  • 3
  • +1
4 Solutions
 
Umar Topia.Net Full Stack DeveloperCommented:
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
KBergerCommented:
Hi,

try Miron Abramson's Compressor/Minifier

http://mironabramson.com/blog/post/2008/06/High-performance-css-minifier.aspx

We are using this component in some of our production-applications. You will just have to install it, make some changes to your web.config. With basic installation and configuration you will have already good results. You can also adopt your aspx-files, so that many single JS or CSS files get combined to one big file, which reduces HTTP-overhead.

Regards,

-Kristof
0
 
AidenAAuthor Commented:
Hi, thanks,.

@umartopia: I'd seen some of those sites before and I'm still not clear on how to go about it from that site to be honest. I looked at the site relating to IIS7 but I wasn't convinced this is was the best way to do it. He was saying things like the site only compresses when hit by two different ip addresses and I wasn't clear whether this was the standard process so moved on.

@CodeCruiser: All those links use C#. The third one is just for minification I think also. Is there no simple way to do this other than use some utility in which I've no real visibility? What do you use yourself for such a task?

@KBerger: This looks like a minifier and also it's in C#. I was more interested in compression and preferably to be able to do it myself so I can understand and control what's going on
0
 
KBergerCommented:
Hi,

well, actually it is a compressor as well (Gzip). What do you mean by "want to control what's going on". Why? The component will compress your content with GZip.
I guess you can download the source-code somewhere and if not, use reflector to look at it.
Why would you take the risk of implementing a component taht has been implemented by others and has undergone bugfixing and production experience?
Are your requirements more special than just "compress my data" ?

Regards,

-Kristof
0
 
CodeCruiserCommented:
In the "How To Use" section of my first link, I dont see any C#.

If you want to understand how it works, try using a C# to VB converter like

http://www.developerfusion.com/tools/convert/csharp-to-vb/
0
 
AidenAAuthor Commented:
ok well i better just pick one of these things to begin with first. @KBerger: Since you've used this before, how do I use it? It looks like just a cs class. What am i doing with this? Is it minifying at runtime before being sent to the client or am I using it before posting to production server?

And, which is better? Presumably it would be better to have the files already minified on the server I presume instead of getting IIS or whatever to zip before it is sent

(also, this isn't using gzip or deflate then?)
0
 
AidenAAuthor Commented:
as an example of something which may (or may not) be simple... take a look at this link

http://www.fiftyfoureleven.com/weblog/web-development/css/the-definitive-css-gzip-method

now, I've never used php and know nothing about it... but what do you guys make of that?
0
 
KBergerCommented:
Hey Aiden,

Hum. it's not a single class. I attached the latest version from CodePlex for your convenience. There are built versions of the dll in the archive as well as a simple demo-applicaton.

You will have to make some changes in your web.config
(as I am not using the latest version, please verify this with the documentation in the attached archive).

Within the section-groups:

    <sectionGroup name="Miron.web">
      <section name="CompressorSettings" type="Miron.Web.MbCompression.SettingsConfigSection" />
    </sectionGroup>

Under httpHandlers:

      <add verb="*" path="jslib.axd" type="Miron.Web.MbCompression.JavaScriptCompressionHandler, MbCompression" validate="false" />
      <add verb="*" path="css.axd" type="Miron.Web.MbCompression.CssCompressionHandler, MbCompression" validate="false" />


Under httpModules

      <add name="WebResourceCompressionModule" type="Miron.Web.MbCompression.WebResourceCompressionModule, MbCompression" />
      <add name="MbCompressionModule" type="Miron.Web.MbCompression.MbCompressionModule, MbCompression" />


And then you will have to add the actual Config-Section:

  <Miron.web>
    <!--cachingStorage="OutputCache / FileSystem"-->
    <CompressorSettings compressCSS="true" compressJavaScript="true" compressPage="true" compressWebResource="true" minifyContent="true" cachingStorage="OutputCache" autoMode="true" scriptsVersion="1" cssVersion="1">
      <excludeTypes>
        <add key="image/gif" />
        <add key="image/jpeg" />
      </excludeTypes>
      <excludePaths>
      </excludePaths>
    </CompressorSettings>
  </Miron.web>

Best regards,

-Kristof

mbcompression-42789.zip
0
 
AidenAAuthor Commented:
Hi,

I managed to solve my problem. Turned out to be ridiculously simple, just had to enable dynamic content compression on IIS as per this blog http://blog.wassupy.com/2009/08/enabling-dynamic-http-compression-in.html and confirmed compression using YSlow. This seems the best solution as IIS7 does the compression itself which means it can either send a compressed or non compressed file to the users browser depending on whether their browser supports compression or not (although i guess these days most must). I'm assuming the other compression techniques could be problematic, although the compression might be overall better... i'm not sure it's really worth it for what i'm doing.

umartopia was closest with his link although the solution provided wasn't the one I went with, a comment on one of the links put me in the right direction.

I'll give some points also for the other solutions as I may want to minify my code before I compress to get the best results. I'm thinking of using jsmin for that just because I've heard it's simple.

Thanks for help!

Aiden

0
 
AidenAAuthor Commented:
experts helped me figure it out, solution is in final comment
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now