IT Community - Software Programming, Web Development and Technical Support

Website Performance Tips & Tricks

This is a discussion on Website Performance Tips & Tricks within the Web Design Help forums, part of the Web Development category; Line breaks we want to know how they can retain textarea line breaks in HTML. You should store text in ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Web Design Help

Register FAQ Members List Calendar Mark Forums Read
  #61 (permalink)  
Old 08-21-2007, 11:59 PM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Line breaks

we want to know how they can retain textarea line breaks in HTML. You should store text in the database in its original format (e.g. with just newlines) and then use nl2br() to convert newlines to HTML <br /> tags on display. That's all good, except for one problem with nl2br(): it doesn't seem to convert \r newlines (edit: this has now been fixed in PHP 4.2.0).

Windows uses \r\n newlines; *nix uses \n; Mac uses \r.

nl2br() works correctly on text from Windows/*nix because they contain \n. However, if you get text from a Mac, nl2br() will not convert its newlines (again, fixed in PHP 4.2.0). To remedy this, we should use the following bit of code to convert \r\n or \r to \n before inserting it into the database. It won't hurt anything and ensures that nl2br() will work on the \n only newlines on display. Also, it has the side effect of saving 1 byte in the database per newline from Windows (by storing only \n instead of \r\n).

PHP Code:
$txt preg_replace('/\r\n|\r/'"\n"$txt); 
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #62 (permalink)  
Old 08-22-2007, 12:13 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Quotes around numeric data in queries

For numeric columns in MySQL, you shouldn't put quotes around any of their values in queries. As most legends says, "that is very non-standard and will only work on MySQL." But if it's unknown data, how do you know that it's numeric and not letters that will cause an error? You can make sure that only a number is used in the query by first type-casting the data as int (or float for decimal numbers):



// If id is being passed in the URL
$id = (int) $_GET['id'];

$r = mysql_query("SELECT * FROM table WHERE id=$id");



Then even if id is set to "abc," the worst that can happen is a 0 will be used in the query. No quotes; no error.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #63 (permalink)  
Old 08-22-2007, 12:51 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

MySQL Column types and attributes

1) Be familiar with MySQL's column types along with their ranges/lengths. You should use the smallest column type that will hold the data that you expect to store. Most of the time, you probably don't need INT, because MEDIUMINT, SMALLINT, or TINYINT have enough range. Using a smaller type saves space and speeds things up.

2) Declare all of your columns NOT NULL unless you need to store NULL values (NULL is not the same as 0 or the empty string). If you need to store NULL, you'll know. Again, NOT NULL saves space and speeds things up.

3) Making INT-family columns UNSIGNED will effectively double the positive range with the same storage requirement. For example, TINYINT's highest value is 127. TINYINT UNSIGNED's highest value is 255.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #64 (permalink)  
Old 08-22-2007, 05:39 AM
kathir kathir is offline
D-Web Trainee
 
Join Date: Feb 2007
Posts: 25
kathir is on a distinguished road
Default Re: Website Performance Tips & Tricks

Efficient Query Design

* Know your data. When writing the SQL statement, you should have some idea of how many rows are in each table, how selective your WHERE predicates are, and how many rows you expect in the result set. The larger the number of rows involved, the more time you should spend thinking about the best way to write the SQL statement.

* Minimize returned rows. The fewer the rows in the result set, the more efficiently the query will run.

* Avoid unnecessary columns. The wider the data in each row in the result set, the more disk space and memory that is required for intermediate operations such as sorts and to hold the result set.

* Use GROUP BY instead of DISTINCT. In most DBMSs, a GROUP BY is a more efficient way to eliminate duplicate rows compared with the DISTINCT keyword. The reason for this is that a GROUP BY invokes the sort required to find the duplicates earlier in the processing of the query, while a DISTINCT applies the sort as the very last step (applied to the final result set). The sooner the duplicate rows are eliminated, the more efficiently the remainder of the processing on that result set can be performed.

* Views may help. Views can help because they hide complex operations such as nested aggregate functions. And with DBMSs that don't have an SQL statement cache, views may process more efficiently than ordinary queries because the SQL statement that defines the view has already been parsed and optimized, which means this work does not have to be done every time the view is accessed. But above all, remember that views are also SQL queries, so they are subject to all the tuning considerations you apply to any SQL statement.
Thanks
-Kathir
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #65 (permalink)  
Old 08-22-2007, 07:54 AM
Booom Booom is offline
Administrator
 
Join Date: Feb 2007
Posts: 74
Booom is on a distinguished road
Default Re: Website Performance Tips & Tricks

Very good contribution has been made to this thread and so ive made this thread sticky.

Good Luck and continue quality content posting in this thread regularly because our goal must be to get the 1st result in search engines when searched for website performance or website performance tips.

Thanks
__________________
Vinoth Chandar
Creator of Discussweb
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #66 (permalink)  
Old 08-22-2007, 08:38 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

  • In PHP4, objects and arrays should be passed in and out of functions by reference (with &), and everything else by value. In PHP5, objects are automatically passed by reference. For example the following gives best performance:
    function &test(&$obj_or_array)
    {
    return $obj_or_array;
    }
    $var =& test($obj);


  • Be miserly and sparse with your server and web pages. Don't run X-Windows on the server and other unneeded processes.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #67 (permalink)  
Old 08-23-2007, 12:12 AM
velhari velhari is offline
D-Web Programmer
 
Join Date: Mar 2007
Location: Chennai
Posts: 67
velhari is on a distinguished road
Send a message via AIM to velhari
Default Re: Website Performance Tips & Tricks

Hi all,
In PhP, When you are working with String, if suppose want to check that the string contain certain length , you considerably use strlen() function. Of course, it is pretty quick method to calculate the length of string. However, it is somewhat slow because the function call require to refer in hash table lookup and then execute that function.

For that case, you can use isset() method to improve the execution speed of your code.
why isset()?
isset() is a language construct and not a function meaning that its execution doesnot refer the lookup table. This means that virtually you have no overhead on calculating the String length
How to acheive?
Its simple, In the following Example, It check for the string having less than 15 character, if it so print 'string having less than 15 characters',

here it is....
PHP Code:
$vString 'I am an Indian'

    
if ( strlen($vString) < 15 )
        echo 
'string having less than 15 characters'
The execution of the above code is slower than the following code.... But both performs the same operation only.
PHP Code:
$vString 'I am an Indian'
             
              
if ( !isset( $vString{15} )  )
        echo 
'string having less than 15 characters'
__________________
Regards,
VELHARI
I am not totally useless. I can be used for a bad example
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #68 (permalink)  
Old 08-23-2007, 05:29 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Website Performance Tips & Tricks:
  • Don't use images when text will do. Reduce your image sizes with a software like Adobe ImageReady or MacroMedia Fireworks. Avoid dithered images as they tend to compress poorly.
  • Spread the workload. Run your SQL server on another machine. Serve graphics and HTML from another low-end computer. If all static content is served from another server, then you can turn off KeepAlives in httpd.conf on the PHP server to speed up disconnects.
  • Use hdparm to tune your hard disk. If you are using a default Linux install, this could speed up your hard disk by 200%. This is mostly useful for IDE hard disks, but some hdparm settings work with SCSI also.
__________________

J.Vijayanand

Last edited by vijayanand : 08-23-2007 at 05:40 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #69 (permalink)  
Old 08-23-2007, 05:35 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Website Performance Tips & Tricks:

Modify the following httpd.conf parameters to:

PHP Code:
# disable DNS lookups: PHP scripts only get the IP address
HostnameLookups off 

# disable htaccess checks
<Directory /> 
     
AllowOverride none  
</Directory
and turn on follow FollowSymLinks and turn off SymLinksIfOwnerMatch (correction by Joshua Slive) to prevent additional lstat() system calls from being made:

PHP Code:
 Options FollowSymLinks 
 
#Options SymLinksIfOwnerMatch 
There are many other httpd.conf tips below.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #70 (permalink)  
Old 08-23-2007, 05:38 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Website Performance Tips & Tricks:

# If you are comfortable patching Apache 1.3 sources, try lingerd. Each Apache process currently wastes a lot of time "lingering" on client connections, after the page has been generated and sent. Lingerd takes over this job, leaving the Apache process immediately free to handle a new connection. As a result, Lingerd makes it possible to serve the same load using considerably fewer Apache processes.

# Increase SendBufferSize in httpd.conf to the size of your largest Web page. Increase your kernel's TCP/IP write buffer size.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #71 (permalink)  
Old 08-23-2007, 06:13 AM
ramkumaraol ramkumaraol is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 98
ramkumaraol is on a distinguished road
Default Re: Website Performance Tips & Tricks

Have you ever waited for a slow Web page to load, given up, clicked the browser's "Stop" button, and then suddenly seen the page appear? Where was it all that time? Pages like that are a good example of how your HTML tags can affect your page load time.

Reason:

By now nearly everyone knows you should use HEIGHT and WIDTH attributes for your image tags. Using these attributes lets the browser allocate space for your image within the page layout. That way the browser can render the rest of the page, leaving a placeholder for the image while it's loading. HEIGHT and WIDTH attributes for your TABLE and TD tags are just as important, for exactly the same reason. These attributes tell the browser how much space to allocate for each table cell. Without them, the browser waits until all the table's contents have been loaded before rendering any of its contents.

* Use the WIDTH attribute for all your table cells.
* If possible, try to use the HEIGHT attribute for table cells. But be careful with this attribute as explained below.
* Avoid nesting tables if at all possible. Nested tables can dramatically increase your rendering time. If you must nest tables, be sure to use the HEIGHT and WIDTH attributes, at least on the inner table.

Setting the WIDTH attribute for a table is most important in the first row, since the browser uses this row to set the column widths for all the other rows. Likewise setting the HEIGHT attribute is most important for the first cell within each table row, since this sets the height for the rest of that row.
Use of the HEIGHT attribute for tables and table cells is a bit risky, since you don't know the size of the browser's default font. If you plan your table layout assuming everyone is using a font size of 12 points, your page may not be rendered correctly for visitors who've changed their default font. Visitors who've set their browser font to 14 points may see text spill over from one cell to another because the text can't fit into the space you allocated.
There are two ways around this:

* Test your page with your browser's default font set to a larger value.
* Use the FONT tag and SIZE attribute to set the font size for each table cell. Use absolute values, such as "SIZE=2," not relative values, like "SIZE= -1."

Thanks,
Ramkumar.B

Last edited by ramkumaraol : 08-23-2007 at 06:19 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #72 (permalink)  
Old 08-23-2007, 07:37 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: Website Performance Tips & Tricks

Hi

I think every one knows display an output statement in php

Print: The print () function is used to output the given argument. It can output all types of data and multiple outputs can be made with only one print () command.

Echo:
The echo () function is used to output the given argument. It can output all types of data and multiple outputs can be made with only one echo () command.
  1. echo() is faster than print() - print() returns a successful return code when it’s done, while echo doesn’t.
  2. print(’something’) is faster than print (”something”) - since you can embed variables into double quotes, on print(”hello $some_var”) PHP parser makes an additional pass over double quotes to ensure there’s no variable to be interpreted.

Thanks
R.Rajan
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #73 (permalink)  
Old 08-24-2007, 08:18 AM
ramkumaraol ramkumaraol is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 98
ramkumaraol is on a distinguished road
Default Re: Website Performance Tips & Tricks

Try to avoid nesting table.When you place a table inside another table, it takes a lot longer for the browser to work out the spacing since it has to wait to read the entire html and then work out the layout. If at all possible, try using CSS to create the columns on your page.

Thanks,
Ramkumar.B
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #74 (permalink)  
Old 08-24-2007, 09:07 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Website performance Tips:

Hardware and Monitoring :
  • Host your website with a company known for performance. Check newsgroups and web host listing sites such as TopHosts (Web Hosting - Find Affordable Web Hosting Providers) for companies known for high performance. In a shared server environment (not dedicated hosting), find out how many other websites are on the same server as yours. Some web hosts will put up to 1 thousand sites on one server.
  • When hosting your own website, install as much physical RAM as possible on the web server. As memory gets cheaper and cheaper by the minute it is one of the most cost effective purchases an IT department can make.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #75 (permalink)  
Old 08-24-2007, 09:09 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default Re: Website Performance Tips & Tricks

Website performance Tips:

Hardware and Monitoring - 2 :
  • When hosting your own website, use quality hardware ??? don t try and save money when purchasing the hardware that will run one of your most valuable assets.
  • When hosting your own website, consider purchasing quality NIC cards which can offload and reduce CPU usage for networking.
  • Monitor your web pages for performance to make more informed decisions. End-to-end testing of your website, e.g. testing of multiple web pages on your website, is essential to understanding weak points and places for improvement.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #76 (permalink)  
Old 08-25-2007, 02:31 AM
ramkumaraol ramkumaraol is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 98
ramkumaraol is on a distinguished road
Default Re: Website Performance Tips & Tricks

Avoid CSS Expressions

CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically. They're supported in Internet Explorer, starting with version 5. As an example, the background color could be set to alternate every hour using CSS expressions.

background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );

As shown here, the expression method accepts a JavaScript expression. The CSS property is set to the result of evaluating the JavaScript expression. The expression method is ignored by other browsers, so it is useful for setting properties in Internet Explorer needed to create a consistent experience across browsers.

The problem with expressions is that they are evaluated more frequently than most people expect. Not only are they evaluated when the page is rendered and resized, but also when the page is scrolled and even when the user moves the mouse over the page. Adding a counter to the CSS expression allows us to keep track of when and how often a CSS expression is evaluated. Moving the mouse around the page can easily generate more than 10,000 evaluations.

One way to reduce the number of times your CSS expression is evaluated is to use one-time expressions, where the first time the expression is evaluated it sets the style property to an explicit value, which replaces the CSS expression. If the style property must be set dynamically throughout the life of the page, using event handlers instead of CSS expressions is an alternative approach. If you must use CSS expressions, remember that they may be evaluated thousands of times and could affect the performance of your page.

Thanks,
Ramkumar.B
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #77 (permalink)  
Old 08-25-2007, 02:45 AM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Default Re: Website Performance Tips & Tricks

Make JavaScript and CSS External:

Should JavaScript and CSS be contained in external files, or inlined in the page itself?

Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.

The key factor, then, is the frequency with which external JavaScript and CSS components are cached relative to the number of HTML documents requested. This factor, although difficult to quantify, can be gauged using various metrics. If users on your site have multiple page views per session and many of your pages re-use the same scripts and stylesheets, there is a greater potential benefit from cached external files.

Many web sites fall in the middle of these metrics. For these properties, the best solution generally is to deploy the JavaScript and CSS as external files. The only exception I've seen where inlining is preferable is with home pages, such as Yahoo!'s front page (Yahoo!) and My Yahoo! (Sign Up - My Yahoo!). Home pages that have few (perhaps only one) page view per session may find that inlining JavaScript and CSS results in faster end-user response times.

For front pages that are typically the first of many page views, there are techniques that leverage the reduction of HTTP requests that inlining provides, as well as the caching benefits achieved through using external files. One such technique is to inline JavaScript and CSS in the front page, but dynamically download the external files after the page has finished loading. Subsequent pages would reference the external files that should already be in the browser's cache.

thanks,
venkatbi
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #78 (permalink)  
Old 08-25-2007, 02:56 AM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Default Re: Website Performance Tips & Tricks

Two types of performance:

1)There's two different ways to look at a website's performance. First of all there's raw server performance. How many page request can a server handle before it collapses under load and more important: how fast can it process them. On a high volume website this aspect of performance is very important because it determines how many users a machine can serve before additional server capacity is needed.

2)The second way to look at performance is what we could call 'perceived performance'. It's the speed at which your site appears to perform to the user. Even if your server is capable of serving all files required to render your website's pages in a visitor's browser as fast as it gets, your site may still appear slow to the user.


thanks,
venkatbi
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #79 (permalink)  
Old 08-25-2007, 03:05 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Cool Re: Website Performance Tips & Tricks

Hi all,
I have designed the web page in asp.net using C#.
When i run that page in FIREFOX, Horizontal scroll bar is appeared but in IE, its not appeared..... i want to disable the horizontal bar in FIREFOX..
How do i do.. Can anyone help me
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #80 (permalink)  
Old 08-25-2007, 03:25 AM
venkatbi venkatbi is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 80
venkatbi is on a distinguished road
Default Re: Website Performance Tips & Tricks

Using single includes for several style sheets or scripts

One solution is PHP script that does the job of collating several scripts or CSS style sheets into a single file.The script is dead easy to use and will cache the collated file for you until you change one of the files included in it. This means that your files are automatically packed, cached and the include file updated when you change them. You get the best of both maintenance and speed without having to change anything by hand.

thanks,
venkatbi
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply