Some people said to me that my website is kinda slow. Before thinking of paying for a faster webhosting program I tried to optimize my graphics. I converted png's to gif's and jpeg's. That helped a bit, but only a little bit. I ran some website speed test/analyzers and I realized that many javascripts were loaded. The prototype.js only is about 70KB.

Is it possible to integrate those .js files into some php file like page.tpl.php or something like that? Will this make my website faster? I realise that if someone wants a dynamic page with ajax and stuff has to pay the speed price.

Is this integration possible?

Comments

vm’s picture

Even if the 70KB was transfered to a tpl.php page, it would be 70KB and on top of that the .js file would be called every time the .tpl.php page was called. Therefore if in page.tpl.php it would be called for every page on your drupal site, even if the .js file is not needed. Thus uneeded overhead.

the question becomes, what method are you using to call the .js file ?

_____________________________________________________________________
Confucius says:
"Those who seek drupal answers should use drupal search!" : )

dimitris_s’s picture

Thank you for your reply.

If I understood what you mean that's the way the javascript files are called :

<script type="text/javascript" src="/misc/jquery.js"></script>

26 js files are loaded as I can see, when I make a "view source" in the page.

edit: Or you can just click on the first link in my signature and tell me if the site is slow ;D

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

vm’s picture

yep, painfully slow even on a broadband connexction and yes, the bulk of it is coming from the .js scripts that have to be loaded.

MY guess, is you are waiting for Drupal 6 which I believe has some sort of .js aggregation as Drupal 5 has .css aggregation.

For your purposes, I'd consider weening some of the modules that are calling so much js. example: the lightbox it loading an entire library soley for a few functions. I'd consider doing something that uses JQuery which is loaded by core any way.
_____________________________________________________________________
Confucius says:
"Those who seek drupal answers should use drupal search!" : )

Christefano-oldaccount’s picture

Good ideas.

The JavaScript aggregation in D6 was backported to D5: http://drupal.org/node/149402

Other things to do is enable mod_gzip or mod_deflate on the server (Apache) to gzip all text files and mod_expires to help cache the site for returning visitors. Check http://whatsmyip.org/mod_gzip_test/ to see how much smaller your pages are with gzip compression enabled.

dimitris_s’s picture

Painfully slow? omg! I had some friends yesterday to test the page with aDSLs 1 and 2Mbit and they said it was loading quite normal like 2-3 secs between pages and a rapid handling of all ajax content..

These are the scripts that are loaded. Consider the lightbox scripts deleted already. Are there any "double" scripts? Is there something below that's not so essential? Even the shoutbox has js... omg :-/

<script type="text/javascript" src="/misc/jquery.js"></script>
<script type="text/javascript" src="/misc/drupal.js"></script>
<script type="text/javascript" src="/modules/drupalit/drupalit.js"></script>
<script type="text/javascript" src="/modules/jquery_update/compat-1.0.js"></script>
<script type="text/javascript" src="/modules/jstools/jstools.js"></script>
<script type="text/javascript" src="/modules/jstools/activemenu/activemenu.js"></script>
<script type="text/javascript" src="/misc/progress.js"></script>
<script type="text/javascript" src="/modules/jstools/activesearch/activesearch.js"></script>
<script type="text/javascript" src="/modules/jstools/jquery.history_remote.min.js"></script>
<script type="text/javascript" src="/modules/jstools/tabs/jquery.tabs.pack.js"></script>
<script type="text/javascript" src="/modules/jstools/tabs/tabs.js"></script>
<script type="text/javascript" src="/modules/jstools/collapsiblock/collapsiblock.js"></script>
<script type="text/javascript" src="/modules/jstools/jquery.cookie.js"></script>
<script type="text/javascript" src="/modules/jtooltips/js/jquery.tooltip.pack.js"></script>
<script type="text/javascript" src="/modules/thickbox/thickbox.js"></script>
<script type="text/javascript" src="/modules/lightbox2/js/prototype.js"></script>
<script type="text/javascript" src="/modules/lightbox2/js/image_nodes_galleries.js"></script>
<script type="text/javascript" src="/modules/lightbox2/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="/modules/lightbox2/js/lightbox.js"></script>
<script type="text/javascript" src="/modules/mysite/mysite_links.js"></script>
<script type="text/javascript" src="/modules/dhtml_menu/dhtml_menu.js"></script>
<script type="text/javascript" src="/modules/shoutbox/shoutbox-form.js"></script>
<script type="text/javascript" src="/modules/shoutbox/form.js"></script>
<script type="text/javascript" src="/modules/jquery_update/collapse-fix.js"></script>
<script type="text/javascript" src="/themes/newsflash/js/jquery.pngFix.js"></script>

Yesterday I tried to install the jlightbox which is using j-query and not prototype. But just after I installed it, when I went to the administration menu there were no options for the Jlightbox module. It's like something in the cache inside drupal.

Christefano I ran the test and I got the following :

http://www.dobro.gr is not gzipped

Page Size: 74 K
Size if Gzipped: 16 K
Potential Savings: 78.38% OMG again,, this is a lot of gain!

So i'm on a webhost. How do I enable mod_gzip? From my php test file I saw this :

_SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate.

Thank you both for ur answers.

UPDATE : I managed to turn on gzip by adding these 2 lines in a php.ini file I have on my server.

zlib.output_compression = On
zlib.output_compression_level=5

I ran the test again and the test said that gzip compression was on! But when I tried to open my site, it gave me only a white page full of "&^#)(*$*" these things... Please help guys :(

UPDATE 2: I inserted this ob_start("ob_gzhandler"); line into sites/default/settings.php and gzip turned on. With firefox and opera everything was smooth. I also asked some friends and said that the site was really fast. But when I tried to open the site with IE7, i got again that white page with the *^%$$#)( ....

any suggestions on how to turn on that mod_gzip compression reliably?

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

Christefano-oldaccount’s picture

Enabling mod_gzip is a server configuration and not browser dependent -- at least not anymore. IE has supported gzipped files for a while.

Sorry to ask the obvious, but did you empty your IE cache or do a Shift-Reload before getting the white screen?

If you're still getting the "white screen of death" you should turn on PHP error reporting to see if it's a PHP-related problem. If you have access to your server's php.ini, set error_reporting to E_ALL and display_errors to On.

If you don't have access to your php.ini, add this to your settings.php:

ini_set("display_errors", 1);

You may want to turn off error reporting by reversing these changes to php.ini or settings.php once you get your site going. It's usually not a good idea for other users to see errors.

dimitris_s’s picture

Thank you for your reply. I finally managed to enable gzip compression by adding the output_handler = ob_gzhandler in my php.ini file and now it works OK. Could you please stroll a little bit in my site and see if it is actually quick? I would really like to have your opinion. Thank you

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

Christefano-oldaccount’s picture

The drobro.gr site isn't working at all at the moment. There appears to be some encoding issue and everything is showing up like:

��������}ksǕ�g����g#��x�-�^=�X+V,9^����`L���H�InQ�$�ɻJ�ʍ���o�KI�%��K����Ẳ{���<�g�@B�F.���}�����?�晓��K����^y鸈D��7�����N��y���WD2�g=��z���DD��y��x|~~>6���N!~��y�����רK��r^.2��#���r��N�������#�dT S����/��`L#߄8�Y^ɜ�%2N"Vp�OE�v�\�b����H��ӣe�365\��"��gV�蹅�Y�5���^�8,�E�qMo�����>���ߑ�Ѩ8��Y�eW��x�d� �"ܪ���VV��B�n�4=�,��?x�.���9�Nk�޲���H����(Y�Yᘥ�$xQt��T$^�s5���l���=#�Qˌe]7"<���.�9˘�T�3� 7�f����y�t�o+�hX��S1<�CG4�����ٳ im�svƱ�6���z����ek��`h�^[n6�7��b>&V�(���Q~��s�G��̦���UhE�4 �,��h_�����

I would undo the steps you took to optimize your site one at a time until it renders properly.

To improve the performance of the site, don't forget that the JS aggregation patch for D5 that I mentioned earlier is an option. It would be good to figure out what's going on now, of course, before further attempts to optimize your site.

dimitris_s’s picture

Aaaarg.. This is because I enabled gzip... Strange though because it was working on me and others fine.. I removed this now.

I have tried with 3-4 different ways to enable gzip, but eventually everyone produces that *^%**(_ page.

So, how can I enable gzip on my drupal site? Should I talk with my webhost? :(

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

Christefano-oldaccount’s picture

Yes, talking to the webhost would be a good idea. The only thing that comes to mind is that setting ob_handler in the settings.php is unnecessary. You can leave the settings.php alone and add this to your .htaccess file:

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude mime      ^application/pdf$
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    mod_gzip_item_exclude file      \.(?:exe|t?gz|zip|bz2|sit|rar)$
</IfModule>
dimitris_s’s picture

Thanks again for your help christefano :)

I' ll talk to my webhost on Sunday [cause I have some other stuff going on right now] and I will update this topic.

The ob_handler was added in php.ini, but no luck. I did as you said and added the code you provided in my .htaccess file but no luck again. I ran the test and it said that gzip was not enabled.. I'm getting quite dissapointed at this time, cause I tried many things and none of them worked and the page has to start getting promoted in a few days. That promotion is sure that'll bring crowds to my website and with these loading times, I can't be anything else but dissapointed.

Again, any suggestion will be greatly appreciated. :-)

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs