Google Secure Pro

By contarc Last update May 22, 2010 — Installed 44,897 times.

Optimizations

in
Subscribe to Optimizations 3 posts, 3 voices



JoeSimmons Scriptwright

Optimizations

  1. Used top scope object to stop reduce scope chain (window.location.href)
  2. Used .replace so the http url isn't in the history, only the https url
  3. Took out Regex (Regex is slow), put in substring
  4. Used variable to quicken substring and lookup
var url = window.location.href;
window.location.replace(url.replace(url.substring(0,7), 'https://'));

 
contarc Script's Author

Thanks for the suggestion. This has been implemented.

 
Erik Vold Scriptwright
FirefoxMacintosh

JoeSimmons wrote:
Took out Regex (Regex is slow), put in substring

No you didn't, the substring is converted into a Regex which is used by replace(), this is slower I believe because the JS engine must convert the provided string into a regex before it can do it's work.

window.location.replace(url.replace(url.substring(0,7), 'https://'));

In the above the substring function needs to lookup 'http://' then 'http://' needs to be converted in to /http:\/\//

Here is what I suggest:

(function(){
var l=window.location;
l.replace(l.href.replace(/^http:/, 'https:'));
})();

using (function(){ ... })(); inside the userscript because some userscript clients may not have a safe scope for the variables we create. There may not be a need for this currently though..

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel