473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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_AGENT'];

if (preg_match("|MSIE ([0-9].[0-9]{1,2})|",$useragent,$matched)) {
$browser_version=$matched[1];
$browser = "IE";
} else if (preg_match("|Opera ([0-9].[0-9]{1,2})|",$useragent,$matched)) {
$browser_version=$matched[1];
$browser = ‘Opera’;
} else if(preg_match("|Firefox/([0-9\.]+)|",$useragent,$matched)) {
$browser_version=$matched[1];
$browser = "Firefox";
} else if(preg_match("|Safari/([0-9\.]+)|",$useragent,$matched)) {
$browser_version=$matched[1];
$browser = "Safari";
} else {
// browser not recognized!
$browser_version = 0;
$browser= "other";
}

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

Thanks all, I appreciate any help. :)
Sep 17 '07 #1
6 1178
aktar
105 100+
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
Sep 17 '07 #2
Atli
5,058 Expert 4TB
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.
Sep 17 '07 #3
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.
Sep 18 '07 #4
I am actually already using this:

[PHP]if(isset($_SESSION['logged_in_email'])){
$loggedin = true;
}[/PHP]

I know how to do it then! :)
Sep 18 '07 #5
Atli
5,058 Expert 4TB
I am actually already using this:

[PHP]if(isset($_SESSION['logged_in_email'])){
$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:
Expand|Select|Wrap|Line Numbers
  1. # Check if the values are already there
  2. if(!isset($_SESSION['Browser'])) {
  3.   # Find the browser info
  4.   # ... Your code here
  5.  
  6.   # Set the session
  7.   $_SESSION['Browser']['Name'] = $browser_name;
  8.   $_SESSION['Browser']['Version'] = $browser_version;
  9. }
  10.  
  11. # Print a browser specific <link> tag
  12. switch ($_SESSION['Browser']['Name']) 
  13. {
  14.   case "IE":
  15.     if($_SESSION['Browser']['Version'] == 7) {
  16.       echo '<link rel="stylesheet" type="text/css" href="ie7.css" />';
  17.     }
  18.     else {
  19.       echo '<link rel="stylesheet" type="text/css" href="ie6.css" />';
  20.     }
  21.     break;
  22.  
  23.   case "Firefox":
  24.     echo '<link rel="stylesheet" type="text/css" href="firefox.css" />';
  25.     break;
  26.  
  27.   default:
  28.     echo '<link rel="stylesheet" type="text/css" href="default.css" />';
  29. }
  30.  
Sep 20 '07 #6
Thanks for that Atil! :)

You did the work for me! Many Thanks.
Sep 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Kin Pang | last post by:
Hi, I have a routine where I'm using a std::map from a pair of ints to double for caching evaluation results. The cache depth could be upto say 1000 in depth. However, my application needs to...
2
by: Sara | last post by:
Hi - I've been reading the posts for a solution to my query, and realize that I should ask an "approch" question as well. We receive our production data from a third party, so my uers import...
100
by: jacob navia | last post by:
As everybody knows, C uses a zero delimited unbounded pointer for its representation of strings. This is extremely inefficient because at each query of the length of the string, the computer...
9
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
9
by: travisperkins03 | last post by:
Hi, I have read somewhere that C code sometimes cannot be compiled to be as efficient as FORTRAN, eg for matrix multiplication, because a C compiler cannot make the assumptions about arrays that...
9
by: burningsunorama | last post by:
Hi guys! This is maybe a too 'academic problem', but I would like to hear your opinions, something like pros and cons for each approach.... ... Recently we've had at work a little talk about the...
2
by: yicong | last post by:
hi,All could you tell me which case is more efficiency?(my tables have no index) And does it has any else case more efficiency? case1: "select sum(Invoice_Production.Quantity) from...
2
by: Jody | last post by:
Hi I've been working on a database which basically incorporates 3 tables to describe say a widget which is either sold or leased. I have the Widget table which stores the information related...
5
by: Jim H | last post by:
When dealing with reference types, is there an efficiency advantage in using a for loop instead of a foreach? I though I read somewhere that when using value types a for loop was more efficient...
43
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.