Neo
Neo

Reputation: 11567

is unescaping a javascript pre-escaped function a bad idea for performance?

I want to pre-escape part of my javascript code and then include it in my page in the form of eval(unescape([code])). would I be sacrificing performance?

Upvotes: 0

Views: 407

Answers (3)

Dagg Nabbit
Dagg Nabbit

Reputation: 76766

Unicode character escape sequences

example

var \u0062\u0061\u006E\u0061\u006E\u0061 = "\u0062\u0061\u006E\u0061\u006E\u0061";

is parsed as

var banana = "banana";

Base-36 decoding

(only for case-insensitive alphanumeric data)

parseInt("banana", 36);
> 683010982

683010982 .toString(36);
> "banana"

This could work for certain types of data if you split it up and delimit the numbers.


Base-64 encoding

You can find an implementation here...

base64_encode("banana banana banana!")
> "YmFuYW5hIGJhbmFuYSBiYW5hbmEh"

base64_decode("YmFuYW5hIGJhbmFuYSBiYW5hbmEh")
> "banana banana banana!"

Base-85 encoding

Packs things a bit smaller than base-64. Less popular format, might have to dig for an implementation or make your own.

Upvotes: 1

Dr.Molle
Dr.Molle

Reputation: 117354

If you want to hide something from spiders, use an external script and setup your robots.txt .

"good" spiders will accept that, "bad" spiders will take a look anyway if they want to.

Upvotes: 1

Matt Ball
Matt Ball

Reputation: 359966

Don't worry about hiding your JavaScript code from spiders. It should be the least of your concerns, especially since they don't bother to look at it (except looking for more links to crawl).

http://googlewebmastercentral.blogspot.com/2007/11/spiders-view-of-web-20.html

Upvotes: 2

Related Questions