Welcome to Virtual Pet List

Wanting to the biggest Virtual Pet forum on then net? Feel free to sign up today.

Sign Up to VPL
  1. online pet game with mmorpg elements
    join a spooky virtual pet site! Are you looking for new virtual pet sites or sim games to play?
    Our latest project the virtual pets blog
    Please follow our Rules
    Help us out by Promoting VPL or by Supporting us!

Coding problem, help needed

Discussion in 'Programming General' started by Hituro, Jun 1, 2012.

  1. Hituro

    Hituro Supporter
    VPL Supporter Pet Game Owner VPL Member

    Joined:
    Feb 1, 2011
    Messages:
    1,429
    Likes Received:
    101
    Trophy Points:
    1,155
    Showcase Items:
    1
    Okay, I have a coding problem I just can't get my head around, so I thought I would throw it out there and see if anyone has any ideas.

    When you load a page on Grophland you may get one or more random events. Some of these events require complex CSS. Since they can appear on any page the CSS is in the main site CSS, taking up pointless room, so I want it out of there. However events are triggered by including a script (events.php) *after* the header file, so CSS for the page is already set. This means I can't remove the CSS to optional stylesheets.

    Now I can move generation of events to earlier in the process, before the header is sent, so I can use optional CSS. However not every page shows events. This means if I generate events before the rest of the page loads then they may not actually get displayed on that page, which could mean some important notification being missed. I don't want to go and change every page (out of hundreds) to pass some value saying they are, or are not, going to display events and messages, but I can't see how else to avoid generating the events on pages that won't show them.

    Any ideas?
     
    support our sponsor and join today
  2. indysolo621

    indysolo621 Elite Member
    VPL Member

    Joined:
    Feb 27, 2011
    Messages:
    1,397
    Likes Received:
    59
    Trophy Points:
    0
    Can you not take the events css out of the header and have it only display if you do have a random event on the page?
     
  3. nobackseat

    nobackseat Senior Programmer
    Senior Programmer VPL Member

    Joined:
    Jan 22, 2011
    Messages:
    508
    Likes Received:
    46
    Trophy Points:
    915
    Location:
    Florida
    Style tags can work in the body, it's not that big of a deal. If you must be politically correct then make the CSS inline and use an older DOCTYPE. Echo it in the same block as the HTML of the actual event itself. Every unnecessary byte adds up to quite a bit when it comes to mobile phones or your site's bandwidth.

    NBS
     
  4. Hituro

    Hituro Supporter
    VPL Supporter Pet Game Owner VPL Member

    Joined:
    Feb 1, 2011
    Messages:
    1,429
    Likes Received:
    101
    Trophy Points:
    1,155
    Showcase Items:
    1
    That might be the best idea, can I do an inline style with an @import?
     
  5. Grotesque

    Grotesque Pet Game Owner
    Pet Game Owner VPL Member

    Joined:
    Oct 17, 2011
    Messages:
    261
    Likes Received:
    75
    Trophy Points:
    0
    Bundle all your css-files to one, compress and timestamp/hash-mark it, thus the browser can do proper caching. You have PLENTY of whitespace and each single asset increases load time.

    This is how we do in our production enviroment:

    http://breepets.net/assets/application-aea34afe3f096fd5877b296b6875aa2e.css

    There are tools out for this kind of stuff. Luckily, Rails does this automagically for me. However, you might also take look at SASS
     

Share This Page