Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other A question about a little script I'm writing.

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #171669
    nixnerd
    Participant

    So, for my new site, I’d like to do something really simple. I’d like to choose a color palette, and then create a list/array of those hex codes. Let’s say… there are six. Then, each time the site loaded… set the background-color to one of those preselected hex codes.

    This is a really simple task… I’m just wondering if I should do it with JS or PHP? Like from a performance standpoint, what do you think?

    I like the idea of doing it with Javascript. It would be really simple. The only real downside is that if someone has it turned off… they’ll get the default color, which really isn’t a big deal at all.

    #171672
    shaneisme
    Participant

    JS or PHP would both be incredibly simple, but the question is really more what the long-term goals are of the site.

    If you’d like ultimate portability, go with JS and make sure you have stock CSS defaults in place

    If you’d like it to always work, but sacrifice moving away from PHP later, go server-side.

    I think you answered your own question when you said “which really isn’t a big deal at all.”

    #171680
    Alen
    Participant

    If you need to persist the data go server-side, have ‘inster solution here‘ serve up json response. Then handle it client-side.

    If you don’t need persistance. Client.

    #171682
    nixnerd
    Participant

    Hmmmm.

    I’ll take a server-side snippet over something client-side any day of the week.

    I see what you’re saying @TheDoc… but I think @shaneisme is right when he says:

    I think you answered your own question when you said > “which really isn’t a big deal at all.”

    I’m completely fine to have a default color. This is just for a little style pop and pizazz. That’s all. Plus, this is just a portfolio/showcase site. Not a huge deal if colors don’t change.

    I like the uber simple nature of the JS way.

    What’s up @AlenAbdula? Are you back stateside now?

    #171683
    Alen
    Participant

    Eagle has landed.

    #171684
    __
    Participant

    I’ll take a server-side snippet over something client-side any day of the week.

    I’ll take the opposite view, and say “offload it to the client” whenever possible. It’s simply better for performance. Making chooseBackgroundColor() a javascript function instead of PHP means taking some load off of your server (admittedly not much, but this sort of thing can add up), and potentially gives you a page that doesn’t even need to invoke the PHP parser anymore. This could also allow the page to be cached more freely, meaning some requests wouldn’t even hit your server.

    edit

    welcome back, Alen! Hope you enjoyed your trip

    #171694
    __
    Participant

    Especially when talking about changing styles, server-side has to be the better option unless you want the possibility of a flash of color change.

    True. Had’t thought of that.

    #171698
    Alen
    Participant

    change of color

    Could be solved by spinner of some kind or transition.

    http://youtu.be/znjy4Kl3IfU

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Other’ is closed to new topics and replies.