Search code examples
phpjavascriptweb-servicesurlencodereducisaurus

Building Reducisaurus URLs


I'm trying to use Reducisaurus Web Service to minify CSS and Javascript but I've run into a problem...

Suppose I've two unminified CSS at:

http:/domain.com/dynamic/styles/theme.php?color=red
http:/domain.com/dynamic/styles/typography.php?font=Arial

According to the docs I should call the web service like this:

http:/reducisaurus.appspot.com/css?url=http:/domain.com/dynamic/styles/theme.php?color=red

And if I want to minify both CSS files at once:

http:/reducisaurus.appspot.com/css?url1=http:/domain.com/dynamic/styles/theme.php?color=red&url2=http:/domain.com/dynamic/styles/theme.php?color=red

If I wanted to specify a different number of seconds for the cache (3600 for instance) I would use:

http:/reducisaurus.appspot.com/css?url=http:/domain.com/dynamic/styles/theme.php?color=red&expire_urls=3600

And again for both CSS files at once:

http:/reducisaurus.appspot.com/css?url1=http:/domain.com/dynamic/styles/theme.php?color=red&url2=http:/domain.com/dynamic/styles/theme.php?color=red&expire_urls=3600

Now my question is, how does Reducisaurus knows how to separate the URLs I want? How does it know that &expire_urls=3600 is not part of my URL? And how does it know that &url2=... is not a GET argument of url1? I'm I doing this right? Do I need to urlencode my URLs?

I took a peek into the source code and although my Java is very poor it seems that the methods acquireFromRemoteUrl() and getSortedParameterNames() from the BaseServlet.java file hold the answers to my question - if a GET argument name contains - or _ they should be ignored?!

What about multiple &url(n)s?


Solution

  • Yes, you need to URL encode your URLs before you submit them as a parameter to another webservice.

    E.g.

    http://google.com
    

    Becomes

    http%3A%2F%2Fgoogle.com
    

    If you do that, no special characters like ?, &, = et cetera survive the process that could confuse the webservice.

    (Not quite sure what you're asking with your second question, sorry.)