Wednesday, February 21, 2007

Prototype Array fun

I must say, I love prototype and I love cliches. Prototype is the best thing since sliced bread. Okay, maybe not the absolute best thing, but it's close. For example, I was pretty mad that javascript doesn't have a function to check if an array key exists like PHP's array_key_exists function, but with prototype, I can come pretty close.

Array.prototype.keyExists = function(key) {
for (var i in this) {
if (i==key) return true;
return false;

Hopefully this is self explanatory as I'm being lazy and I'm not in the mood to write out detailed examples of how to use it.

Monday, February 19, 2007

Apple Leaks Novatel V740 ExpressCard?

If anyone has been careful enough to scrutinize the latest Apple Software Update for WWAN devices, you may have noticed a mysterious Verizon Novatel V740 ExpressCard EVDO Rev A. Now as it seems now, Sprint just started shipping there Rev A devices today according to the folks over at EVDO Info, but there has been no real word about a Rev A ExpressCard solution from Verizon. Hopefully, there is more news about this new device in the future.

Compressed JS and mod_rewrite

Thanks to Joseph Scott's Compressed Javascript article and comments, I've managed to make some headway on making a solution that degrades nicely for browsers that don't support gzipped JS well at this point. Basically, by sticking to

<script type="text/javascript" src="js/prototype.js"></script>

and then letting apache serve up the gzipped file works best for me so far. By adding the following to my .htaccess file in my js directory

<FilesMatch "\\.js.gz$">
ForceType text/javascript
Header set Content-Encoding: gzip
<FilesMatch "\\.js$">
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*)\.js$ $1\.js.gz [L]
ForceType text/javascript

I am able to push the correct headers to the browser as well as determine whether to serve up the js or js.gz version.

This also relies on the fact that a static precompressed gzipped version of the js file is created so there is little overhead required to gzip the file on every request. If the gzipped version of the file doesn't exist, it simply serves up the uncompressed file.

Of course there are a couple of caveats to this as if you change the JS file, you should update the gz file too or you will wonder why your changes aren't showing up.

Have fun!

New stomping grounds

I've decided to start a new blog for my misadventures and ideas. Hopefully something here will inspire you, if not leave you in awestruck. A few warning for those of you who may read this.

I'm not the most politically correct person.
I will offend SOMEBODY at SOME POINT.
I suck with grammar, so don't expect half of my posts to make sense. That's why this is a rambling.

Okay, back to work. Until then...