Author Topic: PHP vs. Javascript and server loading  (Read 949 times)

0 Members and 1 Guest are viewing this topic.

Offline SoMDWx

  • Forecaster
  • *****
  • Posts: 1014
    • Southern Maryland Weather
PHP vs. Javascript and server loading
« on: December 12, 2017, 09:36:25 AM »
Hello All!

We had a storm system that produced snow here in the Mid-Atlantic region this past weekend that brought 800+/day unique visitors to my site. While this is good for the overall visibility of my site, it also brought heavy loading on the servers hosted by ICDSOFT.  While i did not exceed the allotted  server limits, i would still like to decrease the loading even further.

I have several PHP scripts that get executed when my page loads, all of this increases server loads.  I have pondered converting those scripts to javascripts when/where possible to offload the processing.

I would like some insights and constructive inputs to the whys and why nots to do this...


Thanks!


Jim
« Last Edit: December 12, 2017, 10:34:31 AM by SoMDWx »

Offline weather34

  • Forecaster
  • *****
  • Posts: 1068
    • https://weather34.com/homeweatherstation
Re: PHP vs. Javascript and server loading
« Reply #1 on: December 12, 2017, 10:53:33 AM »
hello

run your url through gtmetrix.com its a good starting point and I wouldn't  go down the road just yet of converting your scripts perhaps just some attention needs to be paid to existing processes .gtmetrix is not just about speed it reveals a lot of other stuff that often is ignored or overlooked things like multiple instances of jquery,identical images served from different url s . spend some time studying the results it can be extremely rewarding . Im on ICDSOFT  and many months ago spent days eliminating all the suggested responses the server load is way below any concern however if any of us had 100 or more simultaneous visitors at one point we would expect to see a rapid rise in server load due to the nature that many weather sites (personal) have updates processes in seconds and pull data from many sources and don't always have the best way of structuring the loading sequence often find pages hang whilst waiting for a resources to load from some other url . script DEFER can work wonders if you get it right .
ps CDN save bandwidth but not always improving website loading , best practice beyond most of our reach(COST) is serve all jquery and css, fonts etc from the same CDN .

hope its of help attached a screenshot don't look that bad do just need to spend some time on it....Brian


« Last Edit: December 12, 2017, 10:56:18 AM by weatherist34 »

Offline SoMDWx

  • Forecaster
  • *****
  • Posts: 1014
    • Southern Maryland Weather
Re: PHP vs. Javascript and server loading
« Reply #2 on: December 12, 2017, 10:59:41 AM »
Thanks! I have been through the gtmetrix site and performed many of the optimizations suggested....

Jim

Offline weather34

  • Forecaster
  • *****
  • Posts: 1068
    • https://weather34.com/homeweatherstation
Re: PHP vs. Javascript and server loading
« Reply #3 on: December 12, 2017, 11:08:25 AM »
Thanks! I have been through the gtmetrix site and performed many of the optimizations suggested....

Jim

I would start with the easy ones first the images don't seem like a of saving but you combine all these together then it looks rather bigger and you can grab the optimised versions and replace the ones served from your domain.

attached image

good luck hope you get the load down.


Brian

Offline SoMDWx

  • Forecaster
  • *****
  • Posts: 1014
    • Southern Maryland Weather
Re: PHP vs. Javascript and server loading
« Reply #4 on: December 12, 2017, 04:06:50 PM »
I am trying to "cache" some png images that end with adbanner.png. What is the syntax to expire those images with *adbanner.png?

I ran the gtmetrix aginst my site and the waterfall is still showing those images taking time to load up....

Jim

Offline weather34

  • Forecaster
  • *****
  • Posts: 1068
    • https://weather34.com/homeweatherstation
Re: PHP vs. Javascript and server loading
« Reply #5 on: December 12, 2017, 04:35:31 PM »
I am trying to "cache" some png images that end with adbanner.png. What is the syntax to expire those images with *adbanner.png?

I ran the gtmetrix aginst my site and the waterfall is still showing those images taking time to load up....

Jim

do you mean via htaccess ?

make sure the mod_expires is active

one month = 2592000 seconds

<IfModule mod_expires.c>
ExpiresActive On
</IfModule>

<Files "something.png">
  ExpiresActive On
  ExpiresDefault A2592000
</Files>

and here is another tip if your not already using add this to the top(1st line) of your page if it is php often a miracle worker and reduces load by 60-80%..

<? ob_start("ob_gzhandler");?>

or better if your server likes it

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

this is what I use in almost any PHP site I work with.


GZIP works well but it is an additional load on your server compressing and then uncompressing and so on

Brian




Offline SoMDWx

  • Forecaster
  • *****
  • Posts: 1014
    • Southern Maryland Weather
Re: PHP vs. Javascript and server loading
« Reply #6 on: December 12, 2017, 05:09:27 PM »
<IfModule mod_expires.c>

    ExpiresActive On
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access plus 1 month" 
    ExpiresByType application/javascript "access plus 1 month" 
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType text/css "access plus 1 month"

   <FilesMatch "elninometer-current.gif$">
    ExpiresActive On
    ExpiresByType image/gif "access 1 day"
   </FilesMatch>

   <FilesMatch "^(main_new_1_cache.jpg|main_new_2_cache.jpg|main_new_7_cache.jpg|main_new_8_cache.jpg)$">
    ExpiresActive On
    ExpiresByType image/jpeg "access 300 seconds"
   </FilesMatch>

   <FilesMatch "^(main_new_5_cache.gif|main_new_6_cache.gif)$">
    ExpiresActive On
    ExpiresByType image/gif "access 300 seconds"
   </FilesMatch>

   <FilesMatch "main_new_3_cache.png$">
    ExpiresActive On
    ExpiresByType image/png "access 300 seconds"
   </FilesMatch>

   <FilesMatch "somdwx_banner.png$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>

   <FilesMatch "^(somdwx_banner.png|cdcafeadbanner.png|reichardhiadbanner.png|COAadbanner.png|POGadbanner.png|pennyadbanner.png)$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>

   <FilesMatch "Mail.png$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>

   <FilesMatch "Twitter.png$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>

   <FilesMatch "Facebook.png$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>

   <FilesMatch "adbanner.png$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>

   <FilesMatch "school-bus-1.jpg$">
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
   </FilesMatch>

   <FilesMatch "^(somdwx_m1bg0.gif|somdwx_m1bg1.gif|somdwx_m1bg2.gif|somdwx_m1bg3.gif|somdwx_m1bg4.gif|somdwx_m1bg5.gif|somdwx_m1bg6.gif)$">
    ExpiresActive On
    ExpiresByType image/gif "access plus 1 year"
   </FilesMatch>

   <FilesMatch "(falling.gif|rising.gif|loading.gif|pixel.gif)$">
    ExpiresActive On
    ExpiresByType image/gif "access plus 1 year"
   </FilesMatch>

   <FilesMatch "wrn1.jpg$">
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
   </FilesMatch>

   <FilesMatch "winter_weather.jpg$">
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
   </FilesMatch>

   <FilesMatch "^(somd_icon_none.png|somd_icon_statement.png|somd_icon_advisory.png|somd_icon_watch.png|somd_icon_warning.png)$">
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
   </FilesMatch>