Page 1 of 1

url surrogate

Posted: Tue Jul 09, 2013 12:12 am
by uriadder
I'd like to automatically add a parameter to the links of a certain website by using the surrogate feature.

Example:
Clicking an internal link of a wordpress blog it always redirects from http://www.example.net/blogentry/ to http://www.example.net/blogentry/?ModPagespeed=noscript

To avoid annoying redirections, how do I write a surrogate to add that "?ModPagespeed=noscript" parameter to the url links of that specific site?
I was looking into the "noscript.surrogate.glinks.replacement" surrogate trying to understand how it works. But unfortunately that one removes parts of the url rather than adding stuff, so it wasn't of great help.

Re: url surrogate

Posted: Tue Jul 09, 2013 2:27 am
by Thrawn
You could still adapt that surrogate, but instead of

Code: Select all

a.href.replace(/.*\/url.*[?&](?:url|q)=(http[^&]+).*/,function(a,b)decodeURIComponent(b));
use

Code: Select all

a.href.replace(/$/, '?ModPagespeed=noscript');
Haven't tested it myself, so no guarantees.

Re: url surrogate

Posted: Tue Jul 09, 2013 5:49 am
by uriadder
It does indeed work, thank you!

However, I just realized that "noscript.surrogate.example.sources" actually defines the domain the replacement is working on - in contrast to what I hoped for the linked url itself - which means that every link on example.net gets passed that parameter, even external ones. Unfortunately I have zero experience in JavaScript, but do you know how to exclude the surrogate if the link is not example.net?
Also the parameter doesn't work on links with a hash tag: example.net/blogentry/#comments How would you prevent a surrogate here? Or alternatively how to replace the hash tag with the parameter?

Is it possible to also define globally valid url surrogates by specifying placeholder sources like "noscript.surrogate.example.sources;*" or "noscript.surrogate.example.sources;!@^https?://[^/]+*\..*/" or similar?