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. join a spooky virtual pet game!An upcoming virtual pet site that's owned by one of our moderators, Pepper-head If you're a fan of cats and breeding them, then this sim game is designed just for you Kaylune is open on Sept. 4th
    Check out Icepets!

    Find New Virtual Pet Sites, Sim Games or Role Playing games to Play.
    Other Websites that we own: VirtualPetsBlog - The Admin Effect

Coding problem, help needed

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

  1. Hituro

    Hituro Supporter
    Pet Game Owner VPL Member

    Joined:
    Feb 1, 2011
    Messages:
    1,428
    Likes Received:
    97
    Trophy Points:
    541
    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?
     
    Your banner/button can be located here for an entire month or year, please see our advertising on virtualpetlist thread for more information.
  2. indysolo621

    indysolo621 Elite Member
    VPL Member

    Joined:
    Feb 27, 2011
    Messages:
    1,393
    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:
    453
    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
    Pet Game Owner VPL Member

    Joined:
    Feb 1, 2011
    Messages:
    1,428
    Likes Received:
    97
    Trophy Points:
    541
    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