Posts

Showing posts from October, 2007

[COW] JavaScript define PHP like function

This time my personal COW is a quite totally cross browser function to define a JavaScript constant. With FireFox or Safari a const variable should be nested or global but the most important thing, it cannot be assigned two times const scriptCantChangeMe = "some text"; scriptCantChangeMe = "something else"; alert(scriptCantChangeMe); // some text A constant should be every kind of JavaScript variable and if this feature will be available on future versions of Internet Explorer and Opera, a lot of security problems should be solved (think for example about JSON, Array, Object and every other constructor, method or callback). Unlikely We can't use this feature with Opera browser and, quite more important, Internet Explorer doesn't support JavaScript constants. The only way to create a global scope constant variable with Internet Explorer is using another language: VBScript This IE dedicated language supports PHP like defined constants: scalar values like int...

adsense destructive function!

Google AdSense is a free and cool service and is widely used inside many sites. It allows site managers to get paid while they show their content ... it's great and thank You Google for this service. However adsense uses a function that's probably the most obtrusive one You can use or find while You write JavaScript. This function is exactely this one: function $(b){ for(var a in K){ b[a]=null } } Using them with own objects is absolutely not a problem but what kind of object do You think that b is? The Window one! It's absolutely a non-sense for a service that uses JavaScript inside a closure to respect other libraries and to be free to use every name it needs to be executed! Why this function is an obtrusive monster? We always use third party libraries or We write JavaScript directly but in both cases We (others) should implement a generic Object.prototype inside our code ... just think, for example, to toJSONString prototype, OK ? Now suppose that You write your ...

Upload progress bar with PHP5, APC and jQuery

Yesterday I wrote a little tutorial (Italian language, sorry) that explain how to create an info panel while a file is uploaded. Here You can view final result: While this is the entire archive with everything You need to test by Yourself my code: APCQuery To test them You need PHP 5.2 or greater and APC enabled. Please verify that rfc is enabled too: extension=php_apc.dll apc.rfc1867 = On If You test them locally please remember to try form using big files (from 40Mb to 200M for fast PCs) changing php.ini upload_max_filesize and post_max_size directives (I suppose 200M is enough). If someone is interested about an English version of tutorial I'll try to find time to translate them.

[ES4] ... good by my darlin' toy ...

... and Welcome Control Over Performances !!! I can't wait one more minute ... Go ES4 implementations, GO!

[COW] locAction - hash JavaScript location wrapper

One of the problems using JavaScript and Ajax is history managment and location behaviour. A good solution was found by backbase many months ago, using reserved hash location property to manage correctly interactions and history itself. This COW should be used to manage hash property as a full compilant location, allowing developers to know pathname, search (query string) and in some cases (JavaScript and Opera) hash itself too. You can view a demo in this page comparing native location and wrapped one using locAction callback . Please note that backbase too removed this practice from its site (which problems?) but my locAction proposal is compatible with every kind of JavaScript compatible browser (of course, IE4 and NN4 too). These are few examples: // basic example - standard location href: http://localhost:80/?key=value&other protocol: http hostname: localhost port: 80 pathname: / search: ?key=value&other hash: // basic example - locAction(location) // using http://lo...

[COW] Web RAM - a JavaScript function to share safely strings

This time my COW is really strange as Web concept ... a total size of 256 bytes (seems hilarius?) to share strings inside each browser window. This idea is not so new, I wrote JSTONE few months ago to do something similar, however it seems that JSTONE requires dedicated JSON implementation or something similar to work correctly. Now, let me explain why I wrote this tiny function and for what it should be used for. Random Access Memory window.name is a string always present every time We open a window. The cool, but not so secure, behaviour of this property is that this persists even if We change site or domain or We refresh page using F5. While We use the same window, window name will be available, seems cool? RAM function is capable to save a lot of informations using a Random Access strategy, where the "memory address" is created by yourself, using your personal keyword. Both keywords and saved data can contain every kind of char excepted for \x00 one (End Of String or ...

Worry about gzip ? No problem, packed.it preferes DEFLATE

I didn't test so much DEFLATE version of packed.it service and it seems that this one didn't work correctly with some browser ( ... ehr ... sorry guys ). So I've just fixed deflate version and in my tests it works perfectly ... so perfectly that I choosed to use DEFLATE as first generator option , instead of gzip. It seems that gzip causes too many problems with some version of Internet Explorer while I have not just read anything something about DEFLATE problems too. gzip VS DEFLATE ? Well, it seems that DEFLATE performs a compression quite faster than gzip but packed.it goal is to forget runtime compression ... so this point doesn't matter while decompression speed should be a better plus, again, for DEFLATE. At the same time DEFLATE seems free of has some problems with every compatible browsers ... and as You know, Internet Explorer is compatible with this compression too :-) The result code should be more slim using gzip but We are talking about 2%, max 3%...

packed.it screencast ... (maybe) Yesss!!!

I didn't find a way to create a clean video, probably 450 pixels are not enought to show how does packed.it work? However, I'll try to explain these two screencast. First one - Ext JS Home Page - from 223Kb to 52Kb This video shows a saved version of Ext JS Home Page . This site uses a lot of external CSS, one imported and one in page but not every one is used by JavaScript disabled browsers. Total CSS size is about 93,2Kb while 4 used JavaScript files size is about 130Kb. With packed.it You can create a project using both CSS and JavaScript and the result will be a single file with total size of 52Kb, including both CSS and JavaScript. I didn't add to project Google Analytics unrich.js file but this should be included without problems too saving other 15Kb. As You can see (I hope), the result is even smaller on page, just three tags, using IE5 compatibility one, instead of 8 inside page ... these are few bytes less than original and layout is even more clean than ever. CS...

new packed.it automatic content generator

packed.it service now creates archives with 3 types of automatic content generator: ASP.NET (C#) , PHP (4 or 5) and Python (mod_python and psp or WSGI version). These generators complete packed.it service and are usable with MyMin produced code too if You choose to manage your own projects by yourself. Probably there will be future implementations (Java, Perl, Ruby), however today You can use packed.it to create optimized CSS and JavaScript for more than 80% of hosting solutions. A special thanks to Cristian Carlesso for C# porting, He doesn't like my revision style so much ... but it works perfectly and it's more simple to mantain too (at least for me :D) Have fun with packed.it :-)

MyMin project 1.0.1 available

I've just uploaded last version of MyMin project fixing only JSmin problems with regular expressions when it's not inside a closure, not after '{' or ';' allowing them to parse entire jQuery UI, for example, without problems. This fix has been successfully tested on Python 2.5, PHP 5.2, C# 2 and JavaScript 1.3 You can find MyMin project description in this page while You can optimize CSS and JavaScript in a single file simply using my on-line packed.it service . Have fun with optimizations and please feel free to post a comment if You find some bug using MyMin project, Thank You!

A "little bastard" BUG using JSmin parsers

Update It seems I found a valid fix for "strange" regular expressions. I suppose MyMin will be available tomorrow while packed.it has been just updated with last client version. Have fun with packed.it and please tell me if some source cannot be parsed. -------------------------------------- While I was testing every kind of source and CSS with my last creation, packed.it , I found a bug on JSmin logic, partially recoded inside MyMin project as JavaScript minifier (MyMinCSS and MyMinCompressor seem to work perfectly). This bug seems to be present on every version linked in JSmin page . I found this bug parsing jQuery UI + every CSS with my new service but one JavaScript file has one single, simple problem: function(){return /reg exp with this ' char/;} Bye bye JSmin, regexp will be parsed as string and an error will be raised. The problem is reproducible just with a string that contains only this (so a source that begins and end with these 3 chars): /'/ that's a...

Are You Ready To Pack ?

I'm pleased to announce my last revolutionary project called packed.it ! Just another minifier packer alternative ??? No guys! packed.it goals is to reduce using best practices both CSS and JavaScript sources in a single file . You can write directly on JS area or in CSS one or upload one or more file, choosing which one should be executed before others. Based on MyMin project , a personal revisit of JSmin plus a dedicated compressor and a CSS minifier for C# , JavaScript , PHP or Python languages, packed.it creates a project archive, in zip format, that will contain everything You need to server your files gzipped, deflated or clear for browsers or robots that does not support gz pages. Not only JavaScript ! The innovative packed.it idea is to process both JavaScript and CSS to create a single project file just compiled to be served using gzip, deflate or clear text. In this case your server will not need to do anything, just serve correct file verifying its sha1 summary to ...

Extended parseInt and toString with radix

With JavaScript You can parse a Number using its toString native function. This one supports a radix argument, an integer between 1 and 37. alert( (10).toString(16) // a ); alert( (35).toString(36) // z ); This method should be really useful but should be used to reduce integer size too. The limit of this function is its max usable radix, 36, but is possible to extend this one? Of course :-) alert([ (35).toString(63), // z (61).toString(63), // Z (62).toString(63) // _ ]); My Base63 implementation allows both toString(radix) and parseInt functions to be compatible with maximum possible radix. For possible I mean only these chars: [0-9] [a-z] [A-Z] plus last special char _ These chars are compatible with \w RegExp syntax and this means that You can use less than 60% of chars to rappresent an integer value. var myInt = 123456789012345, myTinyInt = myInt.toString(63); alert([ String(myInt).length, // 15 myTinyInt.length, // 8 myInt, // 123456789012345 myTinyInt // vlzFV_Fx ...