Efficiency and Performance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abshirf2
    New Member
    • Aug 2007
    • 9

    Efficiency and Performance

    Hello all,

    I was just thinking it would be easier (although it would take time) that i create different CSSs for different browsers and call these CSSs via PHP depending on the browser. Is this worth doing?

    This is the current script i am using to detect different browsers. Making a call to this script a page loads everytime: is this efficient?

    [PHP]<?php
    $useragent = $_SERVER['HTTP_USER_AGEN T'];

    if (preg_match("|M SIE ([0-9].[0-9]{1,2})|",$usera gent,$matched)) {
    $browser_versio n=$matched[1];
    $browser = "IE";
    } else if (preg_match("|O pera ([0-9].[0-9]{1,2})|",$usera gent,$matched)) {
    $browser_versio n=$matched[1];
    $browser = ‘Opera’;
    } else if(preg_match(" |Firefox/([0-9\.]+)|",$useragent ,$matched)) {
    $browser_versio n=$matched[1];
    $browser = "Firefox";
    } else if(preg_match(" |Safari/([0-9\.]+)|",$useragent ,$matched)) {
    $browser_versio n=$matched[1];
    $browser = "Safari";
    } else {
    // browser not recognized!
    $browser_versio n = 0;
    $browser= "other";
    }

    print "browser: $browser";
    ?>[/PHP]
    Is there anything else i can do to boost performance?

    Thanks all, I appreciate any help. :)
  • aktar
    New Member
    • Jul 2006
    • 105

    #2
    I can undertand why you'd want to do that. But wouldn't that just increase your workload and introduce inconsistancies in your css design as you have a lot of css to maintain.

    If I were you, I'd stick to a single css and stick to the css features that are tried and tested and supported by most browsers

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      I've always been able to find some way to work around the differences in the major browsers, but I can certainly see why you would want to create on file for each browser.

      I would recommend trying to create one CSS file for all browsers. Most differences can be worked around.

      If, however, you need to use multiple CSS documents, the code you posted looks good. I would suggest that you run that code once and store the results in the SESSION, so that you don't need to run it every time.

      An alternative approach would be to do this with JavaScript. Then the server would not need to run any extra code, it would be executed on the client browser.

      Comment

      • abshirf2
        New Member
        • Aug 2007
        • 9

        #4
        Thank you for your replies guys! :)

        I have tried to use one CSS for different browsers. But it turns out to be a joke! I am only concerned with IE6, IE7 and Firefox 2.0. They all look different, although only slightly between IE7 and Firefox 2.0.

        I have found many CSS hacks and how to get over problems but there are a few things that still need to be sorted out. I also don't want to be limited by browser incompatabilty. I have a great design (if i say so myself!) and i want to get it to work perfectly for most browsers.

        The $_SESSION array is an excellent place to store the browser type since i am actually using it already.

        How will i do this though, if somebody enters my site in a page other than my homepage. How do i test if they are a new unique user?

        More help will be greatly appreciated.

        Comment

        • abshirf2
          New Member
          • Aug 2007
          • 9

          #5
          I am actually already using this:

          [PHP]if(isset($_SESS ION['logged_in_emai l'])){
          $loggedin = true;
          }[/PHP]

          I know how to do it then! :)

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by abshirf2
            I am actually already using this:

            [PHP]if(isset($_SESS ION['logged_in_emai l'])){
            $loggedin = true;
            }[/PHP]

            I know how to do it then! :)
            Yea thats pretty much how I'd do it (except for the email part of course :P)

            Somewhat like this:
            [code=php]
            # Check if the values are already there
            if(!isset($_SES SION['Browser'])) {
            # Find the browser info
            # ... Your code here

            # Set the session
            $_SESSION['Browser']['Name'] = $browser_name;
            $_SESSION['Browser']['Version'] = $browser_versio n;
            }

            # Print a browser specific <link> tag
            switch ($_SESSION['Browser']['Name'])
            {
            case "IE":
            if($_SESSION['Browser']['Version'] == 7) {
            echo '<link rel="stylesheet " type="text/css" href="ie7.css" />';
            }
            else {
            echo '<link rel="stylesheet " type="text/css" href="ie6.css" />';
            }
            break;

            case "Firefox":
            echo '<link rel="stylesheet " type="text/css" href="firefox.c ss" />';
            break;

            default:
            echo '<link rel="stylesheet " type="text/css" href="default.c ss" />';
            }
            [/code]

            Comment

            • abshirf2
              New Member
              • Aug 2007
              • 9

              #7
              Thanks for that Atil! :)

              You did the work for me! Many Thanks.

              Comment

              Working...