RSS

Monthly Archives: August 2009

Weirdest User Agent String (Updated)

>Investigating a reported bug with one of our PensioenPage websites (IE 8 being detected as IE6) I found out the cause of the issue: An IE8 instance returning the following user agent string:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SIMBAR={B81922DF-CABA-4976-8A80-B27BE01CAC7C}; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Creative ZENcast v2.01.01)

Note that there’s both MSIE 8.0 and MSIE 6.0 in the string! This is the weirdest user agent string I’ve ever seen.

Update (August 25, 2009): And I’m not the only one seeing this kind of agent strings, I just noticed a FancyBox mailing list posting with a similar one:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; InfoPath.2)

And if you search for “Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0;” on Google, you can find a lot of similar ones. It’s a strange world.

 

Vim Syntax Highlighting for LessCSS

>Here’s a quick HOWTO for enabling vim syntax highlighting for .less (lesscss) files:

  1. Create the directory ~/.vim/syntax/ if it does not exist yet.
  2. Download the vim syntax file less.vim into that directory, e.g. with the command:
    wget http://leafo.net/lessphp/vim/less.vim
  3. Make sure the following statements are in your ~/.vimrc:
    syntax on
    au BufNewFile,BufRead *.less set filetype=less

That’s all.

Update (Sept. 25, 2009): Here’s a screenshot:

 
Leave a comment

Posted by on 20 August 2009 in howto, less, lesscss, syntax, syntax highlighting, vim

 

Ant Task for Invoking LessCSS (Updated)

>Update (August 26, 2009): I’ve polished the Ant task for LessCSS files quite a bit and implemented support for both lessc and plessc (the LessPHP alternative).

Features:

  • converts .less files to .css
  • supports both lessc and plessc (at least one is required)
  • supports time-outs
  • only processes changed files
  • supports separate source/target directories, with include/exclude patterns

It’s available under de BSD-license for download from github: http://github.com/znerd/lesscss-ant-task/.

Notes:

  • for lessc (tested lessc v1.1.13) to work to fail properly when lesscs fails, a minor change to one of the lessc files is required, this may be resolved in an upcoming version of the task and/or an upcoming version of lessc
  • plessc v0.1.6 works well with the task, but has a rather annoying bug related to negative background positions.

Below is the original blog post.


Here’s some sample code for implementating an Apache Ant task for invoking lesscss:

import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.MatchingTask;

public final class LesscssTask extends MatchingTask {
public LesscssTask() {
setIncludes("*.less");
}

private File _sourceDir;
private File _destDir;

public void setDir(File dir) {
_sourceDir = dir;
}

public void setToDir(File dir) {
_destDir = dir;
}

@Override
protected void execute() throws BuildException {
for (String inFileName : getDirectoryScanner(_sourceDir).getIncludedFiles()) {
File inFile = new File(_sourceDir, inFileName);
String outFileName = inFile.getName().replaceFirst("\\.less$", ".css");
String outFilePath = new File(_destDir, outFileName).getPath();
String inFilePath = inFile.getPath();

log("lesscss: From \"" + inFilePath + "\" to \"" + outFilePath + "\".");

Execute.runCommand(this, new String[] { "lessc", inFilePath, outFilePath });
}
}
}

After defining the lesscss task in your build file (using a taskdef) invoking it is as simple as:

<lesscss dir="src/htdocs" todir="build/htdocs" />
 
Leave a comment

Posted by on 20 August 2009 in ant, apache ant, java, lesscss, task

 

Installing LessCSS on Gentoo Linux

>Here’s a short HOWTO on installing lesscss on Gentoo. As root, execute:

  1. emerge --sync (or skip this if you know you are relatively up-to-date)
  2. emerge rubygems
  3. gem install less

That’s all.

 
Leave a comment

Posted by on 20 August 2009 in gem, gentoo, install, installation, lesscss, linux

 

Prefetching Files Using jQuery

>Since years, Gecko-based browsers have supported link prefetching, while other browsers (notably Internet Explorer) are lacking this function.

Here’s a simple JavaScript-based work-around based on jQuery:

$(document).ready(function() {

// Prefetch all files referenced in [LINK rel="prefetch" href="xyz"] tags...
var $prefetchTags = $('HEAD LINK[rel=prefetch][href]');

// ...starting with the ones that can be done asynchronously via AJAX...
$prefetchTags.filter('[href$=.txt],[href$=.js],[href$=.html]')
.each(function() {
$.ajax({url: this.href, dataType: 'text'});
});

// ...followed by all referenced images,
$prefetchTags.filter('[href$=.png],[href$=.jpg],[href$=.jpeg],[href$=.gif]')
.each(function() {
new Image().src = this.href;
});

It looks for all LINK tags in the HEAD section of the HTML document that have rel="prefetch" set.

Then it processes all HREF attributes, but treating text files and images differently, since text files can easily be downloaded using asynchronous HTTP requests (a.k.a. XMLHttpRequest or AJAX), while this method is not well-suited for fetching binary files.

This approach may be a bit rough on the edges, since I’ve only done limited testing, on Fireefox 3.0/Mac and MSIE 8.0/WinXP.