Payment of ₹ requested by HONEY VIG. Click the link to pay securely via Razorpay: Make 5000 payment Payment of ₹ requested by HONEY VIG. Click the link to pay securely via Razorpay: Make 5000 payment ⭐ If you would like to buy me a coffee, well thank you very much that is mega kind! : https://www.buymeacoffee.com/honeyvig
Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies
Showing posts with label Website performance. Show all posts
Showing posts with label Website performance. Show all posts

Thursday, January 19, 2012

Create a diagonal rotation with CSS transitions and jQuery

Create a diagonal rotation with CSS transitions and jQuery

This article shows us how to turn an unordered list into a rotating diagonal portfolio with CSS3 and jQuery.

One of the hardest tasks any designer undertakes is the creation of his or her own site. It has to be interesting, informative, unique and show the work well. All this while satisfying the toughest critic, yourself.  What set it apart for me was a combination of simple design, extreme focus and technical interest.

I wanted to spend some time on an element that had some technical challenge and integrated well with the site. The diagonal rotating portfolio brought the excitement of taking on a new challenge and paired it with an overall fun way to display content without sacrificing usability. One of the restraints removed from a personal site is dealing with older browsers. Your past work speaks to your ability to code for the IE7s of the world, so your site can really experiment with what’s fresh.  So, let’s dig in and create a diagonal rotation with CSS3 and jQuery.

Semantics and setup

We start with minimal markup. Always make your markup as simple as possible; don’t duplicate elements unless absolutely necessary. Markup should be a semantic outline of your content. With that in mind, here’s all the markup we need:
  1. <ul class="portfolio">
  2.         <li><img src="img/portfolio-1.jpg" alt="Image 1"></li>
  3.         <li><img src="img/portfolio-2.jpg" alt="Image 2"></li>
  4.         <li class="feature"><img src="img/portfolio-3.jpg" alt="Image 3"></li>
  5.         <li><img src="img/portfolio-4.jpg" alt="Image 4"></li>
  6.         <li><img src="img/portfolio-5.jpg" alt="Image 5"></li>
  7. </ul>
There is one simple unordered list of images for the portfolio. A class of “feature” is applied to the list item housing the current highlighted image. That’s it for the HTML, let’s give this list some style.

Create only the large form of your images and use CSS to scale down. In this case all the images are 600 x 300.

  1. }
  2.  
  3.         ul.portfolio li.feature img{
  4.                 height: 300px;
  5.                 width: 600px;
  6.         }
This is applying a series of styles to the list item with the “feature” class to override the inherited styles, and also create the other end of the transition. The negative rotation is canceling out the initial rotation of the list. Setting a high z-index will place this image above the other images in the list, don’t forget the relative positioning to help z-index. We’re also increasing the opacity and size. The result is a really unique list of images ready for action.

Scripting

Now that we have everything set up and looking nice, it’s time to get moving. Take time to set up jQuery, then we’re ready to go. Since the transitions are already coded into the CSS, we only need a small amount of jQuery to make this work.

Our transitions are dependent on the feature class, so we use jQuery to switch classes on click. Here’s the code:
  1. $(document).ready(function(){
  2.        
  3.         $('.portfolio li').click(function() {
  4.                
  5.                 var new_feature = $(this);
  6.                
  7.                 if (!new_feature.hasClass('feature')){
  8.                
  9.                         $('li.feature').removeClass('feature');
  10.                
  11.                         setTimeout(function(){
  12.  
  13.                                 new_feature.addClass('feature');
  14.  
  15.                         }, 500);
  16.                 }
  17.         });
  18. });
We start with the click function. Once a list item is clicked, we want to make sure it isn’t already the current li. After we know it’s a new one, we remove the feature class from the old list item. This causes a transition to occur shrinking and rotating the element back into the structure of the list.

The setTimeout function allows the transitions to occur sequentially as opposed to simultaneously. Once the first event is complete, the clicked li begins to grow and rotate into the values of the feature class. The change in features is complete.

Once you get the basics of the transitions down you can experiment with other properties. You can fade in information about the feature elements or add in next and previous buttons, even apply keyboard shortcuts. The combination of jQuery and CSS3 is a strong partnerships that leaves the door for creativity wide open.

This is just a small step into the world of CSS transitions. Just in the past week I’ve seen amazing examples like beta.theexpressiveweb.com. It’s a great time to be involved in front-end development. I would love to see what you come up with, don’t hesitate to email your experiments.

Tuesday, December 6, 2011

Why Page Weight Still Matters

The dark and mysterious Internet overlords decreed a commandment at the dawn of the Web. All of us followed the rule: thou shalt not create web pages that exceed 50kB in size.
This was understandable back in those unenlightened times. The majority of Internet users had dial-up modems and broadband was an unobtainable dream. Few developers dared go above 100kB, even when fast connections became a reality.
We rarely worry about page weight today. We may use CSS sprites and compressed JavaScript libraries, but only when they’re practical (indeed, do they really make a difference when we fill our pages with 57 Flash adverts?).
But should we care? I recently had the opportunity to work away without a laptop or reliable wifi coverage. Fortunately, I had my trusty Nokia with E/GPRS to help me stay in touch. It’s not 3G, but I didn’t mind waiting for what I thought would be a few extra seconds for pages to load.
fat-laden web pagesBoy, was I wrong. Although email remained usable, accessing the majority of websites was painful. Many pages approached an obese 1MB in size and took a minute or two to appear. I even began to understand why Apple banned Flash — anything that can slim down pages will improve browsing speeds. Perhaps they even considered blocking CSS and JavaScript.
Approximately 10% of Internet users still use dial-up services in the west. That figure is unlikely to drop rapidly; many will be light users or unwilling to pay for a fast connection. There’s also a percentage of users who are unable to access broadband because they live in a remote area.
There’s little need to worry about that 10%, because it’s unlikely to consist of users who are shopping online or using web applications. However, there are two sectors of the community that will experience exponential growth during the next few years:
  1. Internet users from Asia and Africa. Dial-up access and slow broadband will remain prevalent until telecom infrastructures receive a boost.
  2. Those using mobile devices to access the Internet. Connections are improving, but 3G is typically slower than broadband speeds. Besides, the majority of mobile users are either paying per byte or using devices without 3G.
Internet demographics are changing. Although PC/broadband still dominates, the real growth areas are smaller devices with limited processing power and slower connectivity. In the US, mobile data now exceeds voice traffic and Google is predicting that the days of desktop computing are numbered.
It is possible to create a low-bandwidth or mobile version of your website. It may sometimes be impractical or cost more to do, but there are few excuses for not trimming the excess fat from your pages. Reducing page weight makes your application faster and saves hosting costs.
What do you think? Should developers still be concerned about page weight? Should we strive to save every byte? Or are fast connections so ubiquitous there’s little need to care about it?

9 Causes of Web Page Obesity

Broadband speeds are improving but page weight still matters. If your web pages have become a little bloated, spare a thought for those people on slow connections or using mobile devices. Will they buy your services if you make them wait several minutes for your 5MB monstrosity?
It is possible to create mobile or low-bandwidth versions of your website, but few of us have time or resources to create and test multiple versions of content. But there’s little excuse for not keeping in shape — especially when Google could reduce your rank. Leaner pages appear faster, reduce your hosting costs, save your client’s sanity and are environmentally-friendly!
Here are 9 reasons why your site could be piling on the pounds…

1. Over-the-top advertising

We all need to earn a little money but adverts can be the biggest cause of ballooning bandwidth. Most are graphical and many use animation or video to catch the eye.
There are several ways to address adverse advert obesity:
  1. Don’t overdo it. Adverts are distracting and while most web users expect a few, don’t bombard people with dozens of flashing images. Fewer adverts may receive more clicks if your page doesn’t look like promotional puke.
  2. Remove ads which aren’t working. If a huge advert has raised $0.03 in 5 years, perhaps you can make better use of that space.
  3. Try text-based adverts.

2. Inappropriate use of plugins

fat pagesLet’s be frank — I’m talking about Flash. Despite what Apple think, Flash has its good points. But text content, roll-over effects, and simple navigation menus are not the best uses of the technology.

3. Not optimizing images

If there’s one thing I detest, it’s images which haven’t been resized for the web! Digital camera resolutions have reached ridiculously high levels, but no one wants to download a 5,0002 pixel photograph of your dog. Changing the height and width dimensions in the img tag don’t make a difference — you need to resize your images in a graphics package.
When saving, remember to use the best format and highest compression available. In general, photos are better as JPG and graphics are better as PNG or GIF format. However, you will need to experiment with formats and compression rates to squeeze the most from your images.
Finally, keep an eye on Scalable Vector Graphics (SVG). They could revolutionize image production and file sizes if Microsoft keeps its promise to add SVGs in IE9.

4. Not using image sprites

Lots of little images usually sap more bandwidth than a single large image. Each image requires a separate HTTP request/response and most browsers will download a maximum of 4 files at a time. Putting many images into one file then splitting them with the CSS background-position property can save bandwidth. Amazon.com has a great example.

5. Over-reliance on JavaScript frameworks

I’ve nothing against jQuery and similar libraries, but be wary about becoming too dependent on them. Using two or more libraries for effects may also be wasteful.
The W3C website is prime example: it loads a 22Kb file containing jQuery and a plugin to handle basic stylesheet switching. It could have been written in a dozen lines of JavaScript with better browser support.

6. Inefficient HTML

The best HTML is lean, clean and easy to maintain. Your code could be getting out of hand if you find yourself adding 15 nested div tags each with an ID and multiple classes.
WYSIWYG design packages are partly to blame. They have their place, but don’t consider yourself to be a web developer until you have reasonable knowledge of HTML!
Older versions of Visual Studio and ASP.NET web forms can also generate truly shocking and verbose mark-up. Visual Studio has improved, but even previous versions can generate clean code. Be careful when dragging and dropping controls and inspect the resulting HTML.

7. Embedding CSS and JavaScript

CSS and JavaScript should be contained in external files which can be cached and reused throughout every page on your site. There is no excuse for bulking up your HTML with embedded styles and event handlers.
I’d also recommend putting your script tags at the end of the page just before the tag. The page can then be viewed before any scripts are downloaded and executed.

8. Not exploiting CSS cascades or shorthand notation

A little CSS knowledge can go a long way. Novice coders often apply classes to every HTML element and set properties such as font-family within every CSS definition. A little background reading can drastically cut coding time and stylesheet file sizes.
Don’t forget shorthand notation either. The following code snippets are stylistically identical…
Overweight CSS:
  1. #element  
  2. {  
  3.     margin-top: 0px;  
  4.     margin-bottom: 10px;  
  5.     margin-left: 5px;  
  6.     margin-right: 20px;  
  7.     background-color: #aabbcc;  
  8.     background-image: url("myimage.png");  
  9.     background-position: center center;  
  10.     background-repeat: no-repeat;  
  11. }  
Toned-up CSS:
  1. #element  
  2. {  
  3.     margin: 0 5px 10px 20px;  
  4.     background: #abc url(myimage.png) 50% 50% no-repeat;  
  5. }  

9. Not using compression

Your server can gzip files before they’re sent to the browser. HTML, CSS, and JavaScript files can all be compressed by removing comments and unnecessary whitespace. There are many tools and applications to help you squeeze the most from files prior to deployment or automatically at runtime.
Do you know of any other causes of web page obesity? Comments welcome…

Friday, November 4, 2011

How to Make Sites Loading More Faster

How to Make Sites Loading More Faster
How to Make Sites Loading More Faster? It’s one of questions in my mind when i saw my site yesterday. Oh now, my sites is too slowly. What is the problem? I think it too much images in my post. I compare my posting within a lot of images and less one, and i got different loading time. So, the problem is images.
Many people using pictures or photos on their blogs. It can help readers get the inside more easily. It can make your article or content more interesting too. Of course when you optimizing images for search engine, it can be a good traffic source too.
But, as you know, sites loading will become a problem when we using an excessive images. It’s will more slowly. Do we should care about it? Absolutely right, we must care about it. Or you will lose your visitor, traffic and finally lost money. Logically is when we are visiting other people’s blog which have slow loading time, what we will do? I will leave the sites and visit new site in new tab.
I have some contents with a lot of pictures inside, especially when i posted about WordPress themes, design inspiration, and showcases. So, what i must supposed to do? How to make sites loading more faster? Now, i want to share my experience when tried to increase my sites loading yesterday.

How to Make Sites Loading More Faster

  1. Don’t use to much JavaScript.

    Almost webmasters using JavaScript to make an attractive sites. You can put nice slider, picture gallery and many else with it. Also some Adsense program using it, like Google Adsense, AdBrite, Infolinks, etc. To many installed JavaScript, of course will make your sites more slowly. So, i suggest you to remove the unnecessary ones. i have remove some several Adsense program from my sites, like Google Adsense (Ad links type) and Infolink. I decided to remove when i saw my earning stats. Just little bucks that i got from those ads.
  2. Using images optimizer plugins.

    It’s a must when we have a lot of images in our posts. I have use three plugins, WP Smush.it, WP Parallel Loading System, and YS images lazyload (Server Side). It’s really cool. WP Smush.it is a free WordPress plugins to reduce image file sizes and improve performance using the Smush.it API. Every image you add to a page or post will be automatically run through Smush.it behind the scenes. You don’t have to do anything different.
    YSLazyload lazy picture, only loaded after DOM elements finished, and to determine the current window to load and save your bandwidth resources. Since changes in the service side image src attribute, so compatible with all browsers.
    WP Parallel Loading System is a WordPress plugin that will enhance the loading efficiency of your Blog. This plugin will boost the loading time of your Blog. The more images you have the more it will improve.
  3. Using WP-Optimize Database Optimizer.

    All bloggers was to know that every time we save a new post or pages, WordPress creates a revision of that post or page. If you edit a post 6 times you might have 5 copy of that post as revisions. Imagine if your post or pages are long and big. WP-Optimize is a WordPress 2.7++ database cleanup and optimization tool. It doesn’t require PhpMyAdmin to optimize your database tables. It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.
  4. Define image height and width with tags.

    Height and width tags tell the browser exactly how large the image will be, so it can load other elements of the page while the image loads. If you do not define the image size, the browser must wait for the image to load before it can load the text.
  5. Using CSS Sprites

    Why it can be reduce sites loading time? CSS Sprites is a way to reduce the number of HTTP requests made for image resources referenced by your site. It get the image once, shift it around and only display parts of it, saves the overhead of having to fetch multiple images. Try to use CSS Sprite generator to make it for your website.
There are just a simple ways to reduce your sites loading. Maybe if you have another tips to make sites loading more faster, please share it with us in the comments, we’d love to hear your thoughts!

Saturday, October 22, 2011

4 People You Should Ask For Website Feedback



Most people know that good feedback is essential to designing and developing quality websites.
But what constitutes “feedback” can be ambiguous: for some, it is little more than a hasty spell-check; for others, it is akin to submitting and defending a PhD dissertation.
While there is no one-size-fits-all solution for those seeking feedback on their work, there are some proven ways to get helpful input from others.
Here are a few ideas and tools to assist you in your quest for an improved product.
Have more ideas? Please share them in the comments area.

1. Ask Your Mom

I’m serious. Better yet, ask your grandma. Heck, even your plumber would be great! The reason I say this is because you must have people review your website who aren’t part of the web design and development community. Too often, web designers design for their industry colleagues and not for the audiences that their clients are trying to reach.
If you really want quality feedback, go a step further. For every project, try to get feedback from actual members of the audience you are trying to reach. If you are building a website for engineers, talk to engineers. If you are designing for a school, talk to teachers and students.
Admittedly, getting actionable feedback from outside the web design community can be hard (see “How a Web Design Goes Straight to Hell“), but at the very least, these groups might alert you to mistakes you’ve made from misunderstanding the target audience.
A lot is to be said for thinking on your own about an audience’s online habits and aesthetic preferences. But as fruitful as that can be, do it only after you’ve stepped out of your ivory tower and mingled with the Internet’s common folk.

2. Ask a Big Name

Here’s a question: if you could get feedback from anyone in the world, who would it be?
Every person would choose someone different, but I’ll bet almost everyone could whip up a shortlist of people who they would love to bounce a few questions off of. Here’s the more important question: what’s stopping you from asking them? Sure, they may be busy and important, but that doesn’t mean trying to reach them isn’t worth a shot.
I don’t meant to brag, but I’ve been able to get just about everyone I’ve approached to reply to an email or talk by phone for five minutes to discuss a few questions. Sure, it took some digging and out-of-the-box thinking on my part (as well as being extra nice to their personal assistants or secretaries!), but it was well worth it. You would be surprised how accessible such people can be if you show genuine (but not creepy) interest and respect for their time.
Tim Ferris has an excellent section in his book The Four-Hour Work Week and in a post on his blog about reaching out to big names to discuss ideas and ask questions. In the section of his book entitled “Find Yoda,” Ferris gives a few tips for getting big name mentors on the phone (the one he mentions from his own experience is author John Grisham).
Not everyone can do this, but that’s the point: only the most innovative, persistent and courageous will follow through on getting feedback from their heroes, and that is ultimately what sets them apart from the crowd.

3. Ask Yourself

Here’s a seemingly obvious one. You are surely already editing your own work and making adjustments as needed. But are you really stepping back and asking yourself deep critical questions about your work (questions that would likely lead to revisions), or are you coasting on what you think looks good at the moment?
Every designer and developer would do well, upon completing a project, to wait before submitting it to the client. Get as far away from it as you can for a day or two, and then come back to it with fresh eyes.
Waiting until that heat of the moment has passed will uncover problems that you missed earlier or perhaps give you new confidence in elements you weren’t sure about before. Either way, taking a step back and asking yourself critical questions will give you a more thoughtful, deliberate piece of work.

4. Ask Your Community

Whether you work alone or with a team of designers and developers, you need feedback from people who are like you and who do the same kind of work you do.
The feedback you get from fellow members of the community is the most actionable because they know the vocabulary and can give you hard, practical advice (instead of the dreaded verdict one gets from clients, “It needs a bit more pizzazz!”). Your community also understands the various factors that affect your work, like budgets, deadlines and stressful clients.
If you are a freelancer or work alone, getting feedback from the wider community can be frustrating, because you don’t have a dedicated team of colleagues who can review what you’re doing. You’re not alone in this (think of the thousands of other freelancers out there), but there are a few ways to work the situation to your advantage.
One way is to trade feedback. Find a web designer or developer whom you respect, and offer to review their next project in exchange for their feedback on yours (you might not even know them personally—but don’t let that stop you!). Figuring out a system for giving and receiving feedback might take a while, but such a relationship has the potential to become beneficial and second-nature for both of you.

Tools for Collecting Feedback

Most websites, with their forums and comment sections, aren’t ideal places to collect and aggregate feedback. Here instead are a few innovative tools that provide great ways to share and receive feedback on projects and designs.
Concept Feedback - Website Review Community
Concept Feedback is a growing community of design, development and marketing professionals and a welcome change to disorganized forum walls. Concept Feedback allows others to provide quick, actionable feedback on your website via a comprehensive rating system, with the requirement that everyone first give quality feedback before receiving feedback from others. Oh, did I mention that it’s free?

Usabilla
Usabilla allows you to collect feedback for any web page, mock-up, sketch or image. Participants (who you are responsible for finding) simply point and click to share their opinions. Paid plans start at $49 per year, but you can start with five pages for free.

Feedback Army
Feedback Army lets you pose specific questions to a panel of reviewers about anything related to your website. This tool is very helpful for seeing the reactions of others to your website’s particular processes (such as placing an order or signing up for an account). Ten different responses will cost you $10. (UserTesting.com provides a similar service.)

Creattica
Creattica brings together a group of top-notch designers looking to share a wide range of design projects. Membership and participation is free, but feedback is limited to labeling items as “favorites.”

Five Second Test
Five Second Test invites random people to look at your website for five seconds and then give feedback on what they remember of the design and other “prominent elements of your user interface.” Probably not the best tool for in-depth analysis of your work, but a great one to gauge first impressions. Free and paid plans (starting at $4) are available.

Notable App
Notable is a collaborative feedback tool for web designers (similar to ConceptShare and ProofHQ). The free plan includes up to three users, but you’re on your own for finding willing subjects.

Please Critique Me
Please Critique Me is where a panel of web design experts picks out websites from among user submissions to give extensive feedback. They can’t provide criticism to everyone, but submitting your work is certainly worth a shot.

Creating Quality Work

A good web design rarely just happens. It is refined over time by having others (and occasionally you yourself) do everything from kicking the tires to taking it for a full test drive.
Putting aside your ego and opening up to criticism might be hard at first, but feedback from others combined with your creativity make for an excellent product that you and your clients will be proud of.

Thursday, September 29, 2011

Efficient stylesheet minification in C#

I was encouraged to post the code that does the actual minification.
public static string RemoveWhiteSpaceFromStylesheets(string body)
{
  body = Regex.Replace(body, @"[a-zA-Z]+#", "#");
  body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty);
  body = Regex.Replace(body, @"\s+", " ");
  body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1");
  body = body.Replace(";}", "}");
  body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1");

  // Remove comments from CSS
  body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty);

  return body;
}

The method takes a string of CSS and returns a minified version of it. The method have been modified for demo purposes, so you might want to optimize the code yourself.

Performance tuning tricks for ASP.NET and IIS 7

By taking advantage of these few tricks we can increase the performance of any new or existing website without changing anything but the web.config file.
The following XML snippets must be placed in the section of the web.config.

HTTP compression

You’ve always been able to perform HTTP compression in ASP.NET by using third-party libraries or own custom built ones. With IIS 7 you can now throw that away and utilize the build-in compression available from the web.config. Add the following line to enable HTTP compression:

By default, only text based content types are compressed.

doDynamicCompression

Setting this attribute to true enables compression of dynamically generated content such as pages, views, handlers. There really aren’t any reasons not to enable this.

doStaticCompression

This attribute allows you to decide whether or not you want static files such as stylesheets and script files to be compressed. Images and other non-text content types will not be compressed by default. This is also something you want to enable.

dynamicCompressionBeforeCache

If you do output caching from within your ASP.NET website, you can tell IIS 7 to compress the output before putting it into cache. Only if you do some custom output caching you might run into issues with setting this to true. Try it and test it. If your website works with this enabled, then you definitely want to keep it enabled.

Tip

By default, only text based content types are compressed. That means if you send application/x-javascript as content type, you should change it to text/javascript. If you use some custom modules in your website, then you might experience conflicts with the IIS 7 compression feature.

Resources

Cache static files

To speed up the load time for the visitors, it is crucial that everything that can be cached by the browser IS cached by the browser. That includes static files such as images, stylesheets and script files. By letting the browser cache all these files means it doesn’t need to request them again for the duration of the cache period. That saves you and your visitors a lot of bandwidth and makes the page load faster. A well primed browser cache also triggers the load and DOMContentLoaded event sooner.
By adding this snippet to your web.config, all static files are cached in the browser for 1 year:

    

This setting sets the expiration date of the file one year in the future. It does that by setting an HTTP header that instruct the browser to add the file to its internal cache. If you hit F5 or ctrl-F5, the browser will request the files no matter what the expiration is set to.
A major problem with client-side caching is if your static files change before the cache expires. Then the visitor with the old version in the cache won’t see the new file until she clears the browser cache or hit F5. Therefore, this setting must be used with caution and probably with a shorter expiration time. In part 2 of this series I’ll address this problem and provide a simple solution to it.

Tip

Make sure that user sensitive information isn't cached on the browser. It will then be available by anyone else using the same browser.

Resources



==============================================================
In this part we will focus on handling browser caching issues and optimize the number of JavaScript and CSS files loaded from an ASP.NET website. NB! All the code (a single .cs file of 125 lines) is included in the zip file at the bottom of this post.

Browser caching

In part 1, we looked at how it was possible to set an expiration header to any static file such as JavaScript and CSS files, so the browser would cache them for a long time and thereby optimize both for bandwidth and the number of requested files going from server to browser.
The problem with setting a browser cache expiration date of i.e. a JavaScript file to a year in the future becomes clear when you change the file before it expires in your visitor’s browsers. They simply won’t see the changes until they either clear their cache or hits F5 manually.

Adding the version number

The only viable way to maintain a far-in-the-future expiration date is to change the URL of the file when the file changes. So instead of including script files like so:

…we really want to get a version number included in the src attribute, like so:

The problem with this is that ASP.NET doesn’t have any feature that will inject a version number, so we have to create that our selves. It is very simple to do so by looking at when the file was last changed and then retrieve the ticks from that date. In the zip file below you’ll find a method that does exactly that and it can be used like so:

The BundleHelper.InsertFile method is one you want to use for Stylesheets as well, like so:
" type="text/css" />
Ok, now all our JavaScript and stylesheet references have the version number in the path. Next thing to look at is getting it working with the updated non-existing path.

The HTTP handler

To be able to serve the correct file even with the version number in the path, we need to register an HTTP handler in the web.config’s section like so:


The handler we just registered is called FileBundleHandler and knows how to filter out the version number to find the right file. It supports both .css and .js files. The handler also makes sure to both output cache and browser cache correctly. Just add the FileBundleHandler.cs file from the zip file to your website and you are up and running.
Now the browser cache issue has been resolved by adding a version number to the path of the included file and by adding an HTTP handler that knows how to remove it again when serving the file.

Bundle multiple files

Another common website performance issue is that there are many JavaScript and CSS files included on a page. This scenario results in the browser have to download a lot of extra files and that all slows down the performance of a website. The solution to this is also very simple when you’ve first completed the above steps to register the HTTP handler in web.config and called the BundleHelper.InsertFile method when inserting JavaScript and CSS files.

The folder structure convention

There are many ways of bundling files into a single request, like Justin Etheredge’s Squisher. For this example I have chosen a convention based approach because that doesn’t require any code to implement.
Any given ASP.NET website might have a folder structure similar to this:

The folder convention supported in the FileBundleHandler lets you reference a folder instead of just a file. Both the HTTP handler and the BundleHelper.InsertFile understand when a folder is referenced and automatically bundles all the .js or .css files to a single response. So in order to bundle all the files in a given folder, simply reference the folder name and add the extension of the types of files you want bundled. Having the folder structure above, you can add a bundle like so:

Notice that the file /scripts/common.js doesn’t exist, but the folder /scripts/common does. By adding .js at the end, we tell the HTTP handler to look for all files with the same file extension – in this case .js files. It bundles all the files in alphabetical order and serve the as a single response. For security reasons, the HTTP handler will only serve .css and .js extensions.

Minification

Since we are now running all JavaScript and stylesheet files in bundles and through the HTTP handler, it makes sense to also look at the content of the files to optimize even further.
For this example I’m using the Microsoft Ajax Minifier (MAM), which is a single .dll file capable of minifying both JavaScript and stylesheets. The MAM is my favorite JavaScript minifier since it not only removes whitespace, it also rewrites variable and function names and a lot of other things as well. For me it has proven a better choice than the YUI Compressor and Google Closure Compiler. The stylesheet minifier feature of MAM also looks very nice, but I have honestly never used it before except for this example.
Basically what MAM does is that it optimizes and removes unwanted whitespace from both JavaScript and stylesheets. The HTTP handler makes use of MAM for both single files and bundled ones, so you get full benefit no matter your scenario.

Summary

No matter if you use the website model, the web application model or ASP.NET MVC you are now able to utilize the browser cache to the fullest. Furthermore, by bundling your files using the folder convention you can minimize the number of requests sent by the browser. Both JavaScript and stylesheet files are also minified and optimized for even smaller file sizes sent over the wire.
It's worth noticing that the output caching respects file changes and therefore refreshes evertime changes are made to the JavaScript and CSS files tunnelled through this code.
Following the techniques in part 1 combined with this example will improve any website’s server-to-browser performance substantially.

Implementation

  1. Download the zip file below and place the AjaxMin.dll in your bin folder.
  2. Then place the FileBundleHandler.cs in your App_Code folder if you use the website model – otherwise place it where ever it makes sense in your structure.
  3. Now register the HTTP handler in your web.config under the section like so:



  4. The last thing you need is to start using the BundleHelper.InsertFile method on your pages for both JavaScript and stylesheets like so:


    " type="text/css" />