A neat javascript hack

Posted on by in Everything Else

Javascript library publishers often go out of their way to prevent other sites from linking to their libraries directly, preferring anyone who wants to use their library to download and host the file(s) themselves. The most common way to do this is to check the referrer of any requests for javascript files and reject any requests which come from other domains. However, this requires the (minor) extra complexity of requiring server side support.

I just discovered a neat hack in Douglas Crockford‘s popular json2 parser/serializer which obviates the need for any server side support. So simple, yet so effective. Check out the first line of  http://www.json.org/json2.js:

  alert('IMPORTANT: Remove this line from json2.js before deployment.');[/sourcecode]
Neat, eh?


Be the first to write a comment.

Your feedback