Fix Bad value X-UA-Compatible once and for all

If you are still stuck having to support older browsers when developing your brand new sites, or even developing sites for an intranet, then chances are you are using the X-UA-Compatible meta tag. It’s that meta tag that you place in your header to let Internet Explorer know to use a certain rendering engine. There are a few issues with it though, best practices, validation, site speed to name a few… Lets fix this once and for all!


1
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

When Internet Explorer comes across this line it will change the engine that is being used to first Chrome Frame, if the plugin is installed, and then to Edge (the highest supported document mode of the browser). We need to override this in certain situations as by default, any website running on an Intranet will run in Compatibility Mode (Quirks mode) and any website on Microsoft’s Compatibility List will change to it as well.

Note: In Internet Explorer 9 and earlier versions, quirks mode restricted the webpage to the features supported by Microsoft Internet Explorer 5.5. As of Internet Explorer 10, quirks mode behaves differently than the previous versions of the browser. In Internet Explorer 10, quirks mode conforms to the differences specified in the HTML5 specification. For more info, see Specifying legacy document modes.

So If the above line works what is the problem, why should you fix it and what are the reasons you should fix it?

 Validation

One of the first things I notice is that this meta tag is used on quite, a few, websites already, but it causes validation errors when checking against the HTML5 doctype. When checking on Twitter what to do about the X-UA-Compatible entry here are some of the responses I received.

So should you worry about this? Probably not, but it’s easy to fix and I am a believer that if you can fix a validation error then you should.

Note: I agree that validation is only a guide and I too don’t follow it 100%. It is a guideline of best practices, use it as such.

Rendering Speed

The last nail in the coffin for the Meta fix is the overall rendering speed for your pages. Lets say you are on an Intranet so the website will load up in compatibility mode. The browser will request the page and then start downloading as normal, then it will start rendering as normal… until it comes to your meta tag.

The browser will then have to discard anything that it has done and start all over again. This is the same as causing Layout or Style recalculations, it is just another stop along the way to a fast site.

TMI my friend

Too much information! Now days there are a lot of people out there that don’t use Internet Explorer so you just end up sending this data needlessly. Browsers like Chrome, Firefox, Opera, Safari ..etc… just don’t need to see this, but we send it anyway as adding the meta tag is an easy fix for a problem that only occurs on Internet Explorer.

While the extra 62 bytes are negligible, they are still removable and as we know “Every little helps”. As people are increasingly browsing the internet on some form of mobile device, it starts to become more important to think about all of these small wins. For every byte of data we have to wait, it is another ~ms in the delay to a site being usable. Remember just because you have a fast site, doesn’t mean your user has a fast internet connection.

Visitor loss vs page load time - http://www.pearanalytics.com/blog/2009/how-webpage-load-time-related-to-visitor-loss/

Visitor loss vs page load time
http://www.pearanalytics.com/blog/2009/how-webpage-load-time-related-to-visitor-loss/

Just removing this meta tag could save you lots of time overall. A site that I work on gets on average 6 million page views a month and if you multiply that through out the year it is still a saving of over 260mb of data.

The fix

The fix is simple enough but obviously it is not as easy as dropping in a line of HTML. The new fix will be implemented server side and to make this fix complete we need to

  1. Fix the page validation – This is achieved by simply removing the tag
  2. Rendering speed – Instead of waiting for the browser to see the tag and then change modes we will send the correct mode upfront as a response header
  3. Make sure that we only show the fix for Internet Explorer – We will just use some server side browser detection and only send it to IE

PHP

To add the header in PHP we can just add this to our page


1
2
3
if (isset($_SERVER['HTTP_USER_AGENT']) &amp;&amp;
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        header('X-UA-Compatible: IE=edge,chrome=1');

Or you could add it to your .htaccess file like so


1
2
3
4
5
6
<FilesMatch "\.(htm|html|php)$">
    <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
    </IfModule>
</FilesMatch>

You can change the files that are matched and doing it this way will mean the header isn’t set for every resource (images / javascript / css). That should be everything to make sure your site is running good and you are following best practices for a PHP site.

C# (csharp)

You could add in a new customHeader to your web.config file like below, but as far as I am aware you can’t do browser detection in here.


1
2
3
4
5
6
7
8
9
<configuration>
  <system.webServer>
     <httpProtocol>
        <customHeaders>
           <add name="X-UA-Compatible" value="IE=Edge,chrome=1" />
        </customHeaders>
     </httpProtocol>
  </system.webServer>
</configuration>

So the better solution would be to inherit all your pages from a custom Controller (or extend from System.Web.UI.Page if you are using WebForms) and add in the following check.


1
2
3
if (Request.ServerVariables["HTTP_USER_AGENT"] != null &&
                Request.ServerVariables["HTTP_USER_AGENT"].ToString().IndexOf("MSIE") > -1)
                    Response.AddHeader("X-UA-Compatible", "IE=edge,chrome=1");

So that’s it… “ Bad value X-UA-Compatible for attribute http-equiv on element meta.” fixed for good…

In the future we won’t need to include this in our projects but for now we have to just stick with it. Let’s hope that everyone adopts Windows 8 😉

Web Lab Collection

Ok so I have just done a quick impromptu page for Web Labs. I will edit the page shortly and come up with a better layout, but my aim is to get a collection of other peoples web labs, test, experiments, playground folders.

We all have some place that we put our experiments and more people now are turning to services like codepen.io, jsfiddle etc. I just think it would be great to have the more personal list of labs.

If I can get 20 labs I will release the link to my own labs page that just has such random stuff in there. I once did a mashup that merged HTML5 Voice Recognition, JSONP (running through a PHP proxy that retrieved XML), Alice Bot and Google Translation to get an AI that I could talk to and it would talk back to me…

What cool things have you worked on? Want to share your labs let me know in the comments on here or here.

Give your Apache file Index a face lift with h5ai

Are you running an Apache server?

If you are then you would have been greeted by that horrible directory page more than once. Isn’t it time to get rid of the old to make way for the new? Give your Index pages a face lift with h5ai.

h5ai makes browsing directories on HTTP web servers more pleasant

h5ai is a modern replacement for the built in Index view for folder listings and it boast plenty of neat features. It is build with HTML5 Boilerplace, jQuery + Modernizr and can be implemented with just a few steps (2 in my case). It has been created by Lars Jung (@lrsjng) and he has a number of other useful libraries and tools, go check him out.

The design of h5ai is nice and minimal and uses CSS3 and sprinkles of JS to get things working. If you have JS turned off though it degrades nicely. There is a built in colorbox that enables you to view images on the fly and to top it all off there is a code syntax view so you can easily read things like JS and XML.

This definitely makes your index views easier to digest and easier to navigate around as there is a built in search and tree view.

There are plenty of optional features and extensions you can enable with h5ai as seen above where you can enable QR Codes on file hover. The whole install sits in one folder at the root of your site and all you need to do is get your server to add its index file to the index file list. Basically just add this line to your .htaccess

1
DirectoryIndex index.html index.php /_h5ai/server/php/index.php

Here are just some of the optional features that are available

  • breadcrumb for the current directory, linked to all parent directories
  • auto refresh
  • custom header and/or footer for each directory
  • select and download multiple files and folders at once, either as tar or zip archive
  • filter function for the displayed files and folders
  • folder sizes
  • localization with a lot of languages already included
  • link hover states between main view, breadcrumb and tree view
  • display HTTP web server details
  • image preview with keyboard support
  • text file preview with Markdown rendering and keyboard support
  • QR codes on hovering files
  • sort files and folders
  • status bar with additional information about files and folders
  • thumbnails for images, pdfs and movies
  • directory tree view
  • display breadcrumb in the browser title

If your not convinced yet then why not head on over to the official page or check out the Github repo.

h5ai demo

Know of any other cool scripts like this? Let me know so I can get them installed and featured on here.

1 Like no Other Launched

Remember how I posted that Sneak Peek back in September? Well it was for our latest launched website 1 Like no Other! Why not check it out and then come back and read the rest of this article?

I don’t usually do write-ups on the sites that I have worked on but I enjoyed this project so why not.

The homepage for this site has gone through 4 different version that include a CSS3 animated intro, a HTML5 Book where you can click through each page and even a Flash version of the above in hopes that it would be faster to download on slower connections.

1LNO Homepage

The end version the client went for was a subtle parallax effect which works great! It gives you the ability to see all of graphics and illustrations for this seasons clothing. It went through many different revisions and many different layers (9 layers at one point) just goes to show that more is not always better.

1LNO Listing page

The product listing page was also fun to create for this project. The main filter system is pulled in through Ajax to reduce page load and to provide a nicer experience when navigating, who wants a page refresh anyway?

Once an Ajax request is finished all of the products animate to their new locations. This is a great effect and I hadn’t done anything like this before so it was great to learn something new at the same time. Most of the text that is on and around the site in a custom font called Paulson which works really well and is placed on with Cufon.

1LNO Product page

The product page was another nice one to do. I added some subtle animations to the alternate images and to the add to basket just to catch the users eye when they first navigate to it.

We went through a few versions of the carousel at the bottom of the page aswell. This went from a simple left and right carousel, to just one large image in the middle that was more like a zoom of item underneath it. The end version is definitely better and uses the jQuery easing plugin to give the animations a smoother transition.

When the product page was first made we just had a standard zoom on hover effect so that a potential customer could see the detail of the shirts. We found that this didn’t show enough though, instead I created a custom full page zoom to really show them off.

Custom product zoom

Well that’s the main pages of this ecommerce build but I have included more images below for you to look at. Let you know what you think in the comments or even go check out the website for youself and have a look around 😉

CSS Off 2011

I finally got around to uploading my submission for CSSOff 2011 (http://www.unmatchedstyle.com/cssoff/).

I gotta say I’m not happy with it though. It started off really good, but then I got lazy and started putting it off. Next thing I knew I was coding away while Andrew was playing the Rocky theme tune on his phone. The design was really good and everything was meant to be responsive but the bottom half of the site just went wrong. Not through lack of skill, but lack of time.

Have a look for yourself here http://www.validatethis.co.uk/cssoff-2011/

I don’t think the submissions have been marked yet so I don’t know where I came but I will update this when I find out. I’m also going to enter into any other competitions like this so if you know of any then post them in the comments 😉

Sneak Peak

A sneak peak of what I’m working on here at work. I’m having to animate everything but as you can see this has rotations, which are always fun to try and implement into older browsers.



Luckily I found some great plugins for jQuery that make the job a lot easier.

jQuery Transform
https://github.com/heygrady/transform/
This plugin uses CSS3 transforms if they are supported and if not then relies on the matrix filter for IE8 and below meaning it allows you to transform layers all the way down to IE6 and gives you loads of options like


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Go Crazydd
$('#example').transform({
    matrix: [1, 0, 0, 1, 0, 0], //applies a matrix
    reflect: true, //same as rotate(180deg)
    reflectX: true, //mirrored upside down
    reflectXY: true, //same as reflectX + rotate(-90deg)
    reflectY: true, //mirrored
    rotate: '45deg', //rotates 45 degrees
    skew: ['10deg', '10deg'], //skews 10 degrees on the x and y axis
    skewX: '10deg', //skews 10 degrees on the x axis
    skewY: '10deg', //skews 10 degrees on the y axis
    scale: [1.5, 1.5], //scales by 1.5 on the x and y axis
    scaleX: 1.5, //scales by 1.5 on the x axis
    scaleY: 1.5, //scales by 1.5 on the y axis
    translate: ['20px', '20px'], //moves the transformation 20px on the x and y axis
    translateX: '20px', //moves the transformation 20px on the x axis
    translateY: '20px', //moves the transformation 20px on the y axis
    origin: ['20%', '20%'] //changes the transformation origin
});

jQuery Easing
http://gsgd.co.uk/sandbox/jquery/easing/
When animating things its always nice to have more easing options that the standard ‘linear’ or ‘swing’. jQuery Easing gives you around 32 extra easing’s to make your job easier. It also allows you to setup your own custom easings.

Touch it 1 World Plays

I decided to take a night off coding Touch It 2 tonight and instead I tried to experiment with some of the data collected with Touch It 1.

I decided it would be good to visualize where all the players are coming from as this may help when making Touch It 2.

I wanted to be able to see the plays being added to a drawing in realtime so I had a quick search around the net and came across this script.

http://www.patrick-wied.at/static/heatmapjs/

 

Heatmap.js was exactly what I was looking for, it even provided a nice way to draw at certain x y locations. After I had got a quick test knocked together the rest just fell into place.

I used PHP+MySQL to generate a Javascript array which I then looped through with a delay so I could see each dot being added. The end animation is quite good even if I do say so.

I didn’t spend much time trying to tweak the results as I feel the saved PNG shows me what I wanted to know.

Touch It World Plays

That’s it really nothing else special about it… Just a heatmap, move along, nothing more to see here…..