Archive
Generating cache-friendly URLS for parallel image loading
The use of parallel image loading to improve page load time has been documented in multiple places. One of the key things to understand when one is using this technique is to always generate the same URL for the same static asset even if it resides on a different page.
This will allow the end-user to take advantage of HTTP proxy caches.
I wrote these set of simple PHP functions to demonstrate how one could incorporate this when generating the container HTML page for a website which uses parallel static asset loading
<?php
function path_to_origin_suffix($path,$NUM_ALIASES=2)
{
/** Take hex value of md5 of $path. Get the ord value of the last
hex char. Output it mod $NUM_ALIASES
**/
if (1 == $NUM_ALIASES)
return 0 ;
$hex = md5($path);
return ord($hex[31]) % $NUM_ALIASES;
}
function make_url($path,$scheme="http",$origin="static.example.org")
{
/**
Add leading slash to $path. Generate suffix to append to basic
hostname
basic hostname is the phrase before the 1st '.' in $origin
Output a fully qualified URI encased in double quotes ""
**/
$pos = strpos($path,'/');
if ($pos === FALSE || $pos != 0) {
$path = sprintf('/%s',$path);
}
$suffix = path_to_origin_suffix($path);
$array= explode('.',$origin,2);
$host = "$array[0]$suffix.$array[1]";
$abs_href = "$scheme://$host$path" ;
echo "\"$abs_href\"";
}
function test() {
echo make_url("/here/is/foobar") , "\n" ;
echo make_url("here/is/foobar"), "\n" ;
echo make_url("/there/is/foobar") , "\n" ;
echo make_url("/there/was/never/a/foobar"), "\n" ;
echo make_url("/please/mee/it/54"), "\n" ;
}
//test();
?>
<html>
<head><title>Parallel Static Asset Loading</title></head>
<body>
<img src=<?make_url("/john/rambo.gif")?> />
<img src=<?make_url("here/was/john/rambo.gif")?> />
</body>
</html>
Hope this helps
Impact of OpenDNS on CDN services particularly when used in Asia
At work, I am testing a CDN service run by Panther Express. I have been asking various colleagues and friends to run pings,traceroute and send me some HTTP response headers to analyze which Panther POP gets picked up where
Whilst working with a colleague in our Manila office, I found that he was being redirected to a Panther POP in San Jose California instead of being redirected to either a Hong Kong or Singapore POP as I expected.
I asked him for his /etc/resolv.conf entries and when he sent those to me, I found that one of the entries was that of OpenDNS dns cache. Whilst I truly appreciate OpenDNS’s work particularly its PhishTank system and API which we also use as part of SURBL, I think Asian users should understand that if they use OpenDNS then their DNS traffic leaves from the US and Content Delivery Networks like Akamai, Limelight, Mirror Image, Panther Express will route them to their US POP’s instead of their Asian POP’s
Once my colleague removed the OpenDNS entry, he was routed to the Asian POP for Panther Express
Workaround for Quartz Filter not available in Print menu in Leopard
I recently reinstalled my 20″ iMac (last 2006 model) from Tiger to Leopard. Today, whilst trying to print something on my HP PSC 1210 inkjet printer I found that it was not possible to print in black-and-white as I used to do in Tiger because the Quartz filter option was not available in Leopard
Here’s the workaround
-
Go to print the document. Use the item “Open PDF in Preview” item under the PDF Services drop down menu at the bottom left of the print
window. - After the document appears in Preview, choose Save As… from the File menu.
- Either change the name or use the Replace option when prompted. Select the output format as PDF and use the Quartz Filter to select “Black and White”. Click the save button
Not happy with Apple for making it so complicated to print in black and white. Going to send some feedback to them