Friday 27 November 2009

Websiting

Today I was trying to sort out my website to get it working on the webserver. I had forgotten to update the rewrite rules in the site config on the web server, so I had to do that, and there were also quite a few other things that needed changing/adding, which I discovered via trial and error.

One problem I had was that my pages weren't being gzipped. I tried adding 'application/xhtml+xml' to the list of gzip types, but still couldn't get it working. I tried quite a few things and spent quite a while googling and reading things, which seemed to be unrelated to the problem I was having, so eventually I posted to the Nginx Mailing list. I also read a bit of this article, which it was suggested you read before posting a question.

I read this page about using gzip from within PHP, then looked up ob_gzhandler. Reading the PHP Manual, it said
Also note that using zlib.output_compression is preferred over ob_gzhandler().
So I looked up zlib.output_compression, which is a php.ini setting, and set that to on in my php.ini. On my local system using su_php, the change took effect immediately, and I could see my pages were now being gzipped (I was using Fiddler 2 and inspecting the headers to check if things were being gzipped or not). On the Web Server I had to restart php_fcgi for the change to take effect.

After getting gzip working on pages (it was already working okay on js and css files), I turned my attention to google analytics, which was making the browser send cookies with requests to the static subdomains, rather than just the www subdomain. Reading the Google Analytics info, it said

Most cookies are explicitly set with only the name and content attributes defined. When this is the case, the web browser automatically sets the domain for that cookie to the document.host of the web page that sets the cookie, and it sets the path to the root level (/). This is how a default installation of Google Analytics works, such that if you install the Google Analytics tracking code on pages on www.example.com with no customizations, the attributes for the __utma cookie will be:




  • Name: __utma

  • Domain: www.example.com

  • Path: /

Yet this was clearly not the case. I tried following the advice to set the cookie to a specific domain, but couldn't get it working with the jquery google analytics plugin that I was using. I tried both $.ga._setDomainName('www.domain.com') and $.ga.setDomainName('www.domain.com'), but both produced errors saying that they weren't valid methods. When I inspected $.ga in firebug, the only method it had was the load one, as if it hadn't copied all the google analytics methods to itself (which it should do if you look at the debug version of the jquery google analyitics plugin).

So I stopped using the jQuery google analytics plugin, and instead first put the code google says to use straight in the page. This worked okay, but the browser was still sending cookies to the static subdomains (yes, I cleared my cache and cookies each time to check). So I added in the line pageTracker._setDomainName('www.'+DOMAIN);, and now the browser was only sending cookies with requests to the www subdomain.

When that was working okay in the page, I tried moving it into my javascript, by using jQuery's getScript() method, and a callback function to execute the inline script.

I got that working okay, but then found that the browser was requesting the google analytics script on every page load, instead of cacheing it, and it wasn't just checking if the one in the cache was fresh or not - it wasn't cacheing the script at all.

So doing some more googling I found jquery.getScript() does not cache, which says that jQuery doesn't cache scripts by default, but you can modify the getScript() method to allow a third parameter to set whether the script should be cached or not. So I followed that, and it seemed to work.

In the evening I played on Super Mario Bros Wii for ages with Moccle and L. Unfortunately L didn't save it yesterday, and Moccle didn't know, so he had turned off the Wii after L went to bed, and that meant everything we did yesterday we had to do again today. I also watched a bit of Street Fighter The Movie with Moccle, with the Director's commentary on. He said that the story was written in like half a day, and also this was his first movie. He also said that he was working on a movie at the time he got asked to write the story for Street Fighter The Movie, and that contrary to what others said, he had also been offered jobs of other Movies. Before Street Fighter he said he had mainly done commercials and TV.

After watching a bit, Moccle looked him up on IMDB, and he actually wrote the screenplay for Commando (another impossibly good film), and Die Hard (a good film that actually gets good scores on IMDB). He'd also done the Judge Dredd and Tomb Raider films, and Moccle said he'd (that is Steven E. de Souza) done some rubbish films that he (that is Moccle) had seen.

Food
Breakfast: Strawberry crisp oat cereal; cup o' tea.
Lunch: 2x cheese on toasts; cherry tomatoes; Apple; big home-made choc-chip cookie; Fox's Classic; cup o' tea.
Dinner: Herring in sweet mustard sauce (not very nice); fish cake; tinned plum tomato; peas; potato. Pudding was 4x small chocolate eclairs. Coffee; Sainsbury's Caramel Chocolate.
Supper: Cup o' tea; Dark chocolate digestive; shortbread finger.

No comments: