The importance of page speed

December 7th, 2012

Apparently, one of the factors that affects your Google ranking is how long it takes for a page to load.  I doubt this will make an enormous difference to your ranking unless it is very slow, but it is worth considering, especially if you are in a very competitive industry and you are working hard to claw your way to the top.

Google don’t just use statistics from their bots though, they actually use data on load times from their toolbar that runs inside people’s browsers.  That gives them a better idea of how long the page takes to load.

People do care how long it takes for a page to load.  If your website is responsive and pages load instantly, they are more likely to hang around.  If they have to sit and wait, even for a few seconds, they lose patience easily.  That could make quite a difference to your conversion rate.  Equally, Google monitor your bounce rate and how long people stay on your website.  I’m not sure if they use that for ranking, but it is definitely worth bearing in mind.

In addition to worrying about the server hardware and how heavily it is loaded with other websites/services, bear in mind that the following also affect page load times: –

  • server side code that runs when the page renders, especially if you access external systems including databases
  • HTML size
  • size of images
  • CSS size
  • Javascript size
  • number of images/css files/script references on the page
  • distribution of images/css files/script references across different domains (browsers usually limit how many files they will read from a single domain at a time)
  • speed of data loading from other services
  • caching policies and loading common references from CDNs or locally
  • the position of css and script references on the page

OK, so what can you do about all these? There are plenty of articles on these topics, so I’m just going to go through the basics and leave it to you to Google for the latest info.

Minification

If you haven’t already minified your HTML, Javascript and CSS then do so if possible.  This is just a process to remove all unnecessary whitespace to reduce the size.  You can do this dynamically as the page loads, but if you do, make sure your server can handle the load and it is probably sensible to have some sort of caching system.  If you minify code and CSS statically, make sure that you keep a copy of the original for when you need to change it later though!

Javascript packers

These are javascript libraries that pack your code up smaller and unpack it for use.  I’ve not used any myself, but they can save a lot of space in some cases.

Compression

Most web servers can compress HTML, CSS and Javascript, including dynamically generated pages.  Make sure you have this configured (usually gzip/deflate)

Simplify

Have a good long think about whether your HTML is as simple as it can be.  It really shouldn’t need to be a tag soup in order to look good.  You might have to make some minor visual sacrifices to save a lot of complexity.  Think about whether clever use of CSS can save a lot of HTML.

Have a think about whether your CSS is organised well and logically.  Can rules be combined?

Do you need all that javascript still?  Can it be expressed in shorter form?

Images

Can you reduce the number of images?  Is it worth simplifying the design?  Do you actually need all the pixels you have on repeating images (eg. gradients only need to be 1 pixel wide/high, covered areas of images might be croppable).  Make sure you are saving images in an appropriate format and compression level.

Combining files

See if you can combine multiple javascript files together.  Same applies to CSS.  This often has the additional effect of improving overall compression efficiency.

Look into image sprites.

Loading from multiple domains

If you absolutely have to have those 25 images (or javascript/css references) on the page, see if you can spread them across different domains.  Even subdomains work, although a separate domain is a little better as you can make it cookieless and save a few extra bytes on each request.  In fact, loading all references from another domain can save a bit on the cookie overhead.

Local/remote references

Work out whether to have referenced items stored locally (even if on another domain) or loaded from an external source.  Many common libraries, such as jquery are hosted on public CDNs.  There is a reasonable chance that a visitor may have it cached in their browser from there.  On the other hand, some external references may be slow, might not be minified/compressed etc and it may be worth considering whether you can host these yourself (factoring in the pain of having something else to update unless you come up with a clever caching system).  Don’t forget to test this, and don’t forget that your visitors are likely to be coming from all over the world.  If they load a page from the other side of the world, they will be faster accessing a CDN than your local server.

Caching

Make sure that your visitors aren’t needlessly reloading files that haven’t changed too much.  Ensure that you have appropriate headers set up to control caching.  This is a complex subject and you might want to spend some time reading up on it.

Position of CSS/Javascript references

It isn’t obvious, but where you place the CSS and javascript references on the page make quite a difference to load time, because of the way that the browser handles rendering.  CSS should probably be near to the top as it will need to be able to start retrieving this ASAP in order to render the page layout correctly.  Javascript can usually be left to nearer the bottom and you may way to even consider deferring and adding the references dynamically after the page has loaded so that users can start reading while the javascript kicks in (depending on what it does).  Again, other people have written a lot more on this subject.

Testing

There are loads of things that you should test.  Monitor the sizes of the various different files that load, the numbers of files, the load time etc.  Do this using browser tools (many browsers have it built in), external web services such as http://analyze.websiteoptimization.com/wso and http://www.webpagetest.org/ .  Don’t forget that different browsers respond differently, as does different hardware, different platforms (don’t forget mobiles and tablets these days!), different ISPs and different locations.

Some other tools that are worth looking at are YSlow and Google Page Speed.

This can all be pretty time consuming, so the question is whether it is worth it.  It really depends on whether you are having major problems at the moment, how big and important your site is and how much you think it is affecting your visitors.  That’s something that you need to think about and decide on.

Have I missed anything?  Let me know!

MVC, Entity Framework and jQuery

December 7th, 2012

I’ve just started using ASP.NET MVC4 with Entity Framework 5 and jQuery.  I’m finding this is quite a different way of developing web based apps.  I do like jQuery though – it saves a lot of time with Javascript work.

Personally, I would recommend using Code First development with Entity Framework.  It gives you a lot more control over things than letting the designer generate the code.  The ability to use attributes from the System.ComponentModel.DataAnnotations and System.ComponentModel.DataAnnotations.Schema namespaces to automatically generate validation is invaluable to me.  I’m always looking for time saving measures

Five Lies from Three

July 7th, 2011

I hope you’ll excuse me digressing from the usual topic of this blog (again)…

I’m posting this up because it may help other people avoid being ripped off by being told complete nonsense by Three or other mobile phone sellers.  This is as best as I can remember it (next time I am tempted to record the conversation) and I’m sure that there were other things that they lied to me about but I can’t remember everything precisely.

My wife is a UK Three mobile phone customer. I knew that she was approaching the end of her contract, and I am authorised to access her account, so (with her permission), I decided to do a bit of research on what deal would be best for her and then phone up Three to ask when the contract ends.

After over half an hour on hold, I finally got through to someone who told me that she had 44 days left on her contract.  I was quite prepared to say “ok, I’ll call back in a few weeks”, but he wanted to know whether she was happy with her handset.  I explained that she would prefer to have a new one and he started trying to sell me some.  I’d discussed with my wife what she wants and done my research and so I explained that she wants a Nokia X3-02 or C3-01.

He said that the X3-02 is a very nice handset (they sell it), and that he could do me a special deal of £16 a month for 100 minutes, 5000 texts and 2000 Three to Three minutes for 24 months and he wouldn’t charge any extra for getting out of the contract early and he’d give her 2 2gb memory cards.  I told him that T-Mobile would do the C3-01 for £15 a month on an 18 month contract.

(Personally, I think that long contracts are a rip-off.  I usually sell the phone at the end of the contract and they tend to devalue quite a bit from 18-24months.  Also, I don’t see why I should have to pay another 6 months to buy a phone)

First of all, he tried to tell me that it was worth it for the extra 2000 Three to Three minutes, despite the fact that he had noted that my wife barely uses her 35 minutes a month that she currently has and mostly uses her phone for SMS.

First Lie: He tried telling me that OFCOM say that the standard length of a contract is 24 months.  I said that I had read that they said that the maximum length is 24 months which he tried to tell me was wrong.  Having done a bit more research since I got off the phone, I can see that OFCOM actually banned contracts longer than 24 months and insist that all mobile phone networks have options for contracts of as little as 12 months!

Second Lie: He told me that they have to do 24 month contracts to give the phone away free.  I explained that T-Mobile are doing an 18 month contract with a free phone and it is £15 per month.

Third Lie: He told me that the X3-02 is better than the C3-01 because it is newer.  He told me to look at GSM Arena and compare the two.  I did this and pointed out that the C3-01 actually came out a month later (Oct 2010 as opposed to Sept 2010).  He tried to cover this up by saying that the X3-02 has more memory (which is fair enough, but isn’t such a big difference).

He also tried telling me that the X3-02 is better because it has the buttons that are normally on the bottom row (*,0,#) on the right hand side.  That’s highly subjective, but I suppose it isn’t an actual lie.

Fourth Lie: He told me that T-Mobile don’t have their own network and that Three are superior.  Actually, T-Mobile now have 2 networks since they merged with Orange (I’m on T-Mobile) and that means that if you are out of signal with one, you can usually pick up the other.

He tried asking me why I wasn’t willing to pay an extra £1 (I don’t think he actually said per month) and I was about to explain that from my perspective, it is an extra £1 per month = £18 plus the extra 6 months to exit the contract (6 x £16 = £96), totalling £114 extra, which is well worth worrying about.  However, while I had been talking to him, something else had caught my attention online.  I had been looking up what deals Three were doing on their website and I found that they were doing the X3-02 for £15 a month on almost exactly the same deal.  I asked him why he was offering me a worse offer than what was on the website and he said that it was to cover finishing the contract early.  Of course, he’d already told me that he wasn’t charging for this, so it turned out that that was another lie (five lies so far!)   I tried asking him what this customer loyalty discount was, and he said that it was the 2 2gb memory cards.  I pointed out that she already has a 16gb one so they are completely useless.  Also, looking at the figures now, those are worth about £4 each, totalling £8 as against the £114 extra that he was trying to charge me.

At this point I decided to ask for the PAC code to transfer out.  He told me that there would be a £13 charge for finishing the contract early, so I said that I’d call back in a few weeks then (wishing that I’d just gone with my original inclination to say that at the beginning of the conversation).  He said that they do the best deals in the last 30 days of the contract (meaning that he obviously doesn’t care about helping a customer get a good deal otherwise he’d have just told me to phone back in a couple of weeks) and that it might be worth me finding out what the deals were then, but he could still offer me the deal he had today.  I said that I was in no rush and we’d wait a few weeks.  He sounded very surprised and repeated that I’d have to wait a few weeks and was I really sure that I wanted to do that.  I repeated that I was and managed to end the conversation politely.

I hope this has been some use to someone.  Please post comments if you have had similar experiences.  It would be interesting to know what kind of tricks these people get up to to rip people off.

Lessons learned: 

  1. Mobile phone companies will openly lie to keep business
  2. OFCOM say that all customers should have an option of a 12 month contract
  3. Don’t bother calling to haggle an upgrade before the last 30 days as they will just try to rip you off
  4. Customer loyalty can cost you £1 a month (as compared to the cost for a new customer).  Always worth shopping around!

Response from the EU Webmaster

June 14th, 2011

I previously contacted the EU regarding the fact that their websites set cookies without user consent in violation of an EU regulation. (See previous post).

Their response was as follows: –

Dear Madam / Sir,

We thank you for your interest in the European Parliament website.

Indeed, the EU Cookies Directive effective since 25th May 2011 imposes the consent of the User during setup of cookies. We are currently considering the compliancy towards this opt-in policy. The principle of a Guideline is to establish a normative frame imposed to the member states. Then, the national authorities have to enact practical and restrictive measures for websites owners.

Requirement of User consent is not obvious regarding, for example, cookies setup by Google analytics,… In every case, the Institutions have to think in a practical way, about a coherent policy regarding this matter, which can take some time.

Therefore we thank you in advance for your patience.

Best regards,

Europarl Webmaster

EUROPEAN PARLIAMENT
DG COMMUNICATION
Directorate for Media

In other words, it sounds like they don’t know what to do about it either and they are going to wait and see what everyone else does!

Why the EU can’t comply with the EU Cookie Law

May 26th, 2011

You may have heard about the new EU “Cookie Law”. I’m not going to post why it is so idiotic here, I’ll leave you to read about it in other places.

However, I decided that for a laugh I would see if the EU websites comply with the Cookie Law. I looked at 2 of them, and neither of them appeared to. I then decided to contact them via their online chat facility to ask why not. A transcript follows (personal details removed)…

Agent 133:[joined]
Agent 133:Welcome to the EUROPE DIRECT web assistance service. For future reference, your enquiry case ID number is *****.
Agent 133:How can I help you?
****:Hi, I would like to know why this website (europa.eu) and the European Parliament website do not comply with EU directives
****:to be specific, Directive 2009/136/EC Articles 5(3) and 2(5)
****:which state that a user must give explicit consent before cookies are stored
****:however, this site stores a cookie ‘europa_esurvey’
****:and the europarl website stored Google Analytics cookies – ‘__utmz’, ‘__utma’, ‘__utmc’ and ‘__utmb’
****:I was not asked for my consent before any of these were stored
Agent 133:Please wait a moment.
****:ok
Agent 133:I would like to suggest that I forward your enquiry to the European Commission.
Agent 133:Would that be acceptable for you?
****:yes
Agent 133:Would you mind giving me your email address?
****:******@****.com
Agent 133:Is **** your family name?
****:yes – my first name is ******
Agent 133:ok, thank you.
Agent 133:Do you have any other questions regarding this matter?
****:do you have any idea when I should expect a response?
Agent 133:Usually within 3 working days (over 95% of enquiries).
Sometimes we have to send your question to the relevant in-house expert, which takes longer, though no more than 3 weeks.

****:ok, thank you
Agent 133:Are you an IT expert yourself?
****:yes – I’m a computer programmer
Agent 133:ok, I see.
Agent 133:Is there anything else I can do for you?
****:no, that’s all. Thanks
Agent 133:Thank you for using the EUROPE DIRECT web assistance service.
Agent 133:Have a nice afternoon and evening, bye!
****:bye!

I can’t say that I was really surprised that they couldn’t give me an instant answer. I was slightly surprised that they were actually reasonably helpful and fairly friendly (although “Agent 133” seems a bit needlessly anonymous – most firms who have online chat facilities seem to have a surplus of very English names for people who are obviously not native English speakers). I will probably post up when I get a response from them. I’m very curious what it will be!

Microsoft POS Library for .NET

October 14th, 2010

I’ve been writing a specialised point of sale system for a local business and had to use the POS printer on their till.  Fortunately, Microsoft have a nice library available for .NET that is freely downloadable that deals with most of the hard work of communicating with POS devices.

I was interested in the POSPrinter class.  They do provide a simulator so that you can test things out using the simulated printer, but it doesn’t support anything other than basic plain text, whereas I needed to use formatted text.

POS printers usually use a control language called ESC/POS.  This was developed by Epson originally for their POS printers, but it has become a standard.  Basically, it is mostly a matter of sending plain text, but you can also send certain escape sequences to change settings on the printer.

Fortunately, Microsoft document a lot of this on MSDN, so you don’t need to work it all out from scratch.  There are things like knowing that the main escape sequence is &H1B or 27 (known as ESC) and then a pipe character followed by optional numbers, small letters or symbols followed by a capital letter.  Eg. ESC|#P cuts the paper, ESC|bC is the code to turn on bold etc.

However, you may find it useful to have some sample code…


Imports Microsoft.PointOfService

Public Class POSPrinter

    Public Const ESC = Chr(&H1B) & "|"
    Public Const SetBold = ESC & "bC"
    Public Const SetUnderline = ESC & "uC"
    Public Const SetItalic = ESC & "iC"
    Public Const SetCentre = ESC & "cA"
    Public Const SetRight = ESC & "rA"
    Public Const ResetFormatting = ESC & "N"

    Public Shared Function SetSize(ByVal Size As Integer) As String
        Return ESC & Size & "C"
    End Function

    Public Shared Function GetAndInitPosPrinter() As Microsoft.PointOfService.PosPrinter
        Dim pe As New PosExplorer()
        Dim ppdi = pe.GetDevice(DeviceType.PosPrinter, My.Settings.PrinterName)
        Dim pp As Microsoft.PointOfService.PosPrinter = pe.CreateInstance(ppdi)
        pp.Open()

        pp.Claim(250)

        pp.DeviceEnabled = True

        Return pp
    End Function

    Public Shared Sub ReleaseAndClosePosPrinter(ByVal pp As Microsoft.PointOfService.PosPrinter)

        pp.Release()

        pp.Close()
    End Sub

    Public Shared Sub PrintTest()

    Dim pp As Microsoft.PointOfService.PosPrinter = Nothing

    pp = GetAndInitPosPrinter()

    Dim msg As String = "This is a test" & vbCrLf & SetBold & SetSize(3) & SetCentre & "it works" & SetSize(1) & " pretty well" & vbCrLf & "OK"

    pp.PrintNormal(PrinterStation.Receipt, msg)

    ReleaseAndClosePosPrinter(pp)

    End Sub


One other thing to watch out for is that if you are running any other POS software on the till, such as Microsoft Dynamics POS, then you might need to go into the settings and tell it to share the printer nicely with the other children applications as some POS software tends to be pretty possessive

Also, always make sure that you release and close any POS devices when you are done with them. For some reason when you start using them you need to open them, claim them and then enable them which seems ridiculous overkill to me, but what do I know?

Electricity Monitoring Part 2

October 13th, 2010
This entry is part of a series, Electricity Monitoring»

I previously mentioned that I have an electricity monitor and that I wrote a program for collecting the data and uploading it to a central database.  Actually, since then, Google have launched Google PowerMeter.  Fortunately, their API is freely available and so I have uploaded my data into their system (fortunately this was a fairly straightforward XML upload job) and switched to using the Current Cost software for uploading to PowerMeter.

PowerMeter is fairly good, although it does have some annoyances.  However, between that and the other software that I used to use of my own, I have managed to reduce our daily elecricity consumption from about 23kWh to around 11-14kWh.  We pay 7.57p/kWh, so that translates to an annual saving of roughly £275.  We’ve done this without making any major changes to our lifestyle or habits and it doesn’t involve driving yourself mad over little things.  We’ve also done it without switching to compact fluorescent bulbs which I particularly dislike.

Without doubt, the most significant cost savings came from switching off a second freezer which we had running in our shed and from replacing our faulty fridge with one that works correctly.  However, there were were other things that we’ve done that add up to a fairly large amount of electricity saved over time.

The most useful thing that I did was spent a couple of hours one morning doing an electricity audit – working my way around the house working out how much electricity different things use in different states.  Basically, I did this by unplugging everything until the monitor showed zero constantly and then plugged things back in one at a time.  Be careful when you do this if you decide to – make sure no one else is in otherwise you’ll drive them mad and also don’t take too long over it if you have a fridge and freezer otherwise your food will go off!

I found some interesting things, some of which fit in with what other people say and some are surprisingly not mentioned by anyone.  I went as far as measuring different states for several devices – on, standby and off.  That’s one interesting thing – people don’t mention that a lot of devices do use power and in some cases a significant amount of power when they are off, even if they are not in standby.  I’ll write more about this in future posts.

Entries in this series:
  1. Electricity Monitoring Part 1
  2. Electricity Monitoring Part 2
Powered by Hackadelic Sliding Notes 1.6.5

Companies House Electronic Filing Problems – recent annoyances

October 6th, 2010
This entry is part of a series, companies house problems»

As I mentioned in my previous post, I’ve been doing quite a bit of work for a limited company formation agent over the years and have had to deal with some annoying problems.  Please excuse these rants…

Recently Companies House introduced the ability to do company name changes electronically.  This is a very useful feature, except that the XML schemata that they released for them are wrong – the one for submission contains (or at least contained) a field that shouldn’t have been there and isn’t used for anything, and the one for retrieving responses had no way of getting the updated certificate of incorporation, although this information was actually returned in the response.  I’m not quite sure why they bother publishing specifications if they don’t stick to them!

Entries in this series:
  1. Companies House Electronic Filing Problems Part 1 - Introduction
  2. Companies House Electronic Filing Problems - recent annoyances
Powered by Hackadelic Sliding Notes 1.6.5

Linq to SQL Query gives an InvalidOperationException with message “Cannot compare entities associated with different tables.”

September 15th, 2010

If you try to do a Linq to SQL query and it runs fine, but gives you an exception of type InvalidOperationException and the message is “Cannot compare entities associated with different tables.” then it probably means that you are trying to pass in an object of one type and compare it to another type.  I suspect that you will probably only get this error if Linq attempts to translate the error to SQL – if you run it in memory, you might not get an error at all, as it may just do a straight object comparison and conclude that they are different objects.

An example would be something like


Dim p = DBContext.People.First
Dim q = From a in DBContext.Addresses Where a Is p
Dim addr = q.First

The final line will result in this exception as Linq to SQL is attempting to translate the query into SQL and it (correctly) can’t find any way of writing a query that compares a person to an address!

App_Offline.htm – ScottGu’s Blog

September 7th, 2010

I just had an interesting message when working on an ASP.NET 2.0 website – “This application is currently offline. To enable the application, remove the app_offline.htm file from the application root directory.

I’m not sure how this happened, but it looks like it may have something to do with this… App_Offline.htm – ScottGu’s Blog.