I'm building a Ruby on Rails page where there is a list of users, and I'd like to assign a random color to each user based on his email address so that the random color is the same for that user across sessions but different between users.
I've decided that I could digest the email in MD5 and take the first 6 characters. This should give me the same hex for the same email every time, and the hex will be different for different emails.
Now, I'm trying to decide whether I want to do this on the server side (in Ruby) or on the client side (in JavaScript). On the one hand, I already have a lot of JavaScript running on the page so I don't want the page to look too slow, but on the other, I don't want to bog down the server every time this page is loaded. In the rails console, calculating the MD5 of a string isn't super duper fast. It took a second to return something. I guess my questions are:
- Generally, how computationally expensive is creating an MD5 of a string?
- Is there a significant reason to do the digest in the client-side code vs the server-side?
It might sound like I'm over-optimizing here, which is probably true, but I'm also just curious whether there is a rule that I should follow when making decisions like these.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire