Performance tips for web applications

59 thoughts on “Performance tips for web applications”

  1. Pingback: Ehab's Playground
  2. You’ll want to be careful with some of those suggestions. For example, the initial release of WinXP doesn’t work with compressed JS and/or CSS in some circumstances. For our site, that’s 15-20% of the traffic or about as much as FireFox, for us, as a relative example.

    You’ll want to pull & check user agent strings in your PHP code (look for the SV1 which indicates at least WinXP SP2) or configure mod_deflate (what we did) appropriately.


  3. @andrew

    Thanks, yeah I have seen the examples at mod_deflate page. As it is for basic idea, I didn’t go that details.🙂

    and hey, Thanks for the WinXP tips. Didnt know that!

  4. Interesting reading. But screw using java to remove the white space from javascript. This isn’t 100% perfect as some javascript regex and some instances of urls within strings get comfused with javascript comments and are stripped. However these instances can be fixed by minor javascript workarounds and are few and far between.

  5. /**
    * Compresses code (ie javascript and css) whitespace.
    * @param string $code
    * @return string
    function compressCode($code)
    // Remove multiline comment
    $mlcomment = ‘/\/\*(?!-)[\x00-\xff]*?\*\//’;
    $code = preg_replace($mlcomment,””,$code);
    // Remove single line comment
    $slcomment = ‘/[^:]\/\/.*/’;
    $code = preg_replace($slcomment,””,$code);
    // Remove extra spaces
    $extra_space = ‘/\s+/’;
    $code = preg_replace($extra_space,” “,$code);
    // Remove spaces that can be removed
    $removable_space = ‘/\s?([\{\};\=\(\)\\\/\+\*-])\s?/’;
    $code = preg_replace(‘/\s?([\{\};\=\(\)\/\+\*-])\s?/’,”\\1”,$code);
    return $code;

  6. @buggedcom

    well, there are many online compressor too. but afaik, rhino is mozilla’s builtin javascript parser and team dojo modified it to do the job effectively.

    thanks for your snippet.

  7. Thanks for posting this tip vaiya. Looks straight forward. I am sure the concepts will help any web developer to build sites for high performance.

  8. I have found ‘minify Javascript’ point most interesting and didn’t know about Rhino.. so that will defiantly help to make our site much efficient. thanks, nice post!

  9. Really great articles and cool examples.

    I would really like you to expand on the
    6. Move Scripts to the Bottom topic and how it could be done for js with variables and inline htmls. Thanx in advance.

    One of my first reads on javascript taught me to avoid ‘onload’ in body and replace the function call with script tags just before the body tag closes. I guess this is a very good example for ‘Move Scripts to the Bottom’

  10. Is S3 a true CDN? It doesn’t have an SLA and when I ping it from different parts of the country, the responses seem to come from the same datacenter rather then datacenters closer to where the request was made from.

  11. omg, i am so later reader
    anyway bro, the write up was important because now these days people are developing many web applications for community.

    so after getting a lot of user base the service turns in to the slowest one. the performance concerns are really encouraging. obviously premature performance tuning always cost a lot of bucks😉

    i really need to point again about “expire” tip, the expire is one of powerful tools for ajax or heavy javascript, css, image driven site.

    thanks for reminding the right position for scripting or DOM related functionalities. it really scale for browser.

    best wishes;

  12. Salam Bhai Kamon achen?
    ekta doubt ache hasin bhai,

    I have install the wordpress in the root of my website , which works fine.

    But now I want to create a page in a folder which is located outside of wordpress folder( in the root), name ” portfolio” , so how can i get the wordpress theme template applied to those pages in the portfolio folder. ?? with all the header, footer ,background and sidebar???

    Could you help???

  13. Hasin Bhai,

    From your articles, I want to try to follow in my Codeigniter based Application. To apply this things I have some question.

    Gzip components:

    To apply gzip compression, I found in CI config.php

    By default,
    $config[‘compress_output’] = False;
    But If I do
    $config[‘compress_output’] = True;
    Do I have to anything more?

    Add an Expiry Header

    Can I set Expiry Header in a config?
    I found that in download helper they add expiry header:

    // Generate the server headers
    if (strstr($_SERVER[‘HTTP_USER_AGENT’], “MSIE”))
    header(‘Content-Type: “‘.$mime.'”‘);
    header(‘Content-Disposition: attachment; filename=”‘.$filename.'”‘);
    header(‘Expires: 0’);
    header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
    header(“Content-Transfer-Encoding: binary”);
    header(‘Pragma: public’);
    header(“Content-Length: “.strlen($data));
    header(‘Content-Type: “‘.$mime.'”‘);
    header(‘Content-Disposition: attachment; filename=”‘.$filename.'”‘);
    header(“Content-Transfer-Encoding: binary”);
    header(‘Expires: 0’);
    header(‘Pragma: no-cache’);
    header(“Content-Length: “.strlen($data));

    So if I Use do download helper then do I change the value of :
    header(‘Expires: “.gmdate(”D, d M Y H:i:s”, time()+600)” .” GMT”’);
    header(‘Cache-Control: max-age=600’);
    can I set this things in config.php ?

    Making fewer HTTP requests and Config ETags:

    In your example you show , how to do fewer http request using . .htaccess to cache all the things.
    Can I Making fewer HTTP requests and Config ETags in config.php ?

  14. for /F %%F in (’dir /b *.js’) do java -jar custom_rhino.jar -c %%F > %%F.packed 2>&1
    What was your OS for this command?
    if its windows,
    what is the name of the quotes you have used here ’dir /b *.js’ ?
    let me know it in my mail please.
    It’ll help me.

  15. Usually, they are able to muster a smug fog of self-righteousness to get themselves to their preferred opinions and to make each other feel warm an superior. ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s