Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing parameters in the URL

Tags:

c#

asp.net

The urls on my site can become very long, and its my understanding that urls are transmitted with the http requests. So the idea came to compress the string in the url.

From my searching on the internet, i found suggestions on using short urls and then link that one to the long url. Id prefer to not use this solution because I would have to do a extra database check to convert between long and short url.

That leaves in my head 3 options:

  1. Hashing, I don't think this is a option. If you want a safe hashing algorithm, its going to be long.
  2. Compressing the url string, basically having the server depress the string when when it gets the url parameters.
  3. Changing the url so its not descriptive, this is bad because it would make development harder for me (This is a 1 man project).

Considering the vast amount possible amount of OS/browsers out there, I figured id as if anyone else has tried this or have some clever suggestions.

If it maters the url parameters can reach 100+ chars.

Example:

mysite.com/Reports/Ability.aspx?PlayerID=7737&GuildID=132&AbilityID=1140&EventID=1609&EncounterID=-1&ServerID=17&IsPlayer=True

EDIT:

Let me clarify atm this is NOT breaking the site. Its more about me learning to find a good solution ( Im well aware this is micro optimization, my site is very fast atm ) and making my site even faster ( To challenge myself, and become a better coder ).

There is also a cosmetic issue, I personal think that a URL longer then the address bar looks bad.

like image 638
EKS Avatar asked Jan 13 '10 12:01

EKS


People also ask

What are URL parameters?

Also known by the aliases of query strings or URL variables, parameters are the portion of a URL that follows a question mark. They are comprised of a key and a value pair, separated by an equal sign.

How does http compress content?

To do this, HTTP uses a mechanism similar to the content negotiation for end-to-end compression: the node transmitting the request advertizes its will using the TE header and the other node chooses the adequate method, applies it, and indicates its choice with the Transfer-Encoding header.

What is the use of urlsearchparams?

They can contain information such as search queries, link referrals, user preferences, etc.. The URLSearchParams interface makes it easier to get the parameter of the URL. It provides methods for working with the query string of a URL.

How do I run a [URL_parameters] query from my dashboard?

Click Run Query and save it. Please note, the URL parameters are applied only in your dashboard, and not during chart creation/editing. Based on the values passed in your dashboard's URL, ubiq will automatically substitute those filter values in [url_parameters] during run time. For example, if your dashboard URL is:


2 Answers

You have some conflicting requirements as you want to shorten/compress the url without making it less descriptive. By the very nature of shortening the URL, you will, to a certain extent, make it less descriptive.

As I understand it, your goal is to optimise by sending less over the request. You mention 100+ characters, instead of 1000+ which I assume means they don't get that big? In which case, I'd see this as an unnecessary micro-optimisation.

To add to previous suggestions of using POST, a simple thing would be to just shorten the keys instead of using full names if you don't want to do full url shortening e.g.:

mysite.com/Reports/Ability.aspx?pid=7737&GID=132&AID=1140&EID=1609&EnID=-1&SID=17&IsP=True

These are obviously less descriptive.

But like I said, are you having a real problem with having long URLs?

like image 78
AdaTheDev Avatar answered Sep 30 '22 08:09

AdaTheDev


I'm not sure I understand what's your problem with long URLs? Generally I'd try to avoid them, but if that's necessary then you won't depend on the user remembering it anyway, so why go through all the compressing trouble? Even with a URL of 1000 chars (~2KB) the page request won't be slow.

I would, however, consider using POST instead of GET if possible, to prettify the URL, but that's of course depends on your implementation / environment.

like image 20
synhershko Avatar answered Sep 30 '22 10:09

synhershko