Bypassing the Safari/WebKit caching bug

Anyone who has used Safari (or any other WebKit-based browser) to debug javascript has encountered the annoying “Resource interpreted as other but transferred with MIME type application/x-javascript” bug. When this happens, the source of the javascript file appears blank in the debugger, and various other things may go wrong (sometimes code isn’t executed, for example).

screen shot

This problem is caused by a WebKit bug, triggered when files are taken from the browser’s cache rather than from your server. The simple workaround is to force WebKit not to cache your javascript files while you’re debugging them. This is easy if you server supports PHP (it almost certainly does). Create a php file to serve your javascript, and have your test page include that instead of your javascript:

Before:
<script src="testing.js" type="text/javascript"></script>

After:
<script src="debug.php/testing.js" type="text/javascript"></script>

Where debug.php has:


<?php
header('Content-Type: application/x-javascript');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
readfile(dirname(__FILE__).'/testing.js');
?>

Or, more generally:


<?php
header('Content-Type: application/x-javascript');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
$file = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/testing.js';
readfile(dirname(__FILE__).$file);
?>

If you use the general version, you may wish to include some security checks on the input (PATH_INFO) to protect against potential exploits. That is left as an exercise for the reader.

Of course, before you deploy, remember to change the script include back to the original form!

Photoluna 1.1

Photoluna 1.1 was released a few weeks ago, and is now available on the iTunes App Store. If you purchased version 1.0, you’ll be happy to know that this upgrade is free, and many of you have already updated to the new version.

Regrettably, I’ve been a bit behind the curve updating the Photoluna web site; most of the screen shots are from version 1.0. I was off on a two-week stint of jury duty just as 1.1 hit the store, followed by a bad cold that led straight into the holidays! The page should be updated soon.

Photoluna 1.1 is (almost) here

Good news for those of you waiting for the next version of Photoluna! We finished and submitted version 1.1 last week, and it is currently under review by Apple. If all goes well it should be available within the next week. We have our fingers crossed.

“But how much will the upgrade cost,” you ask? Nothing! This upgrade will be free to all current customers.

“What’s in the upgrade?” Ah, for that, you’ll have to wait a little longer…

October “Blahs” Sale

Photoluna, for iPhone and iPod Touch, is on sale right now for 50% off (on top of the every-day 20% discount from its release price). This sale will only last a few days, so act quickly!

Photoluna End-of-Summer Sale

Photoluna, for iPhone and iPod Touch, is on sale right now for 60% off. This sale will only last a few days, so act quickly!

« Older entries § Newer entries »