Conditionally load script and style will decrease memory usage?

So my wordpress site front page is using almost 100mb memory usage according to New Relic. I want to lower this number. Obviously, when I disable plugin entire, it lower the number of memory usage. But all my plugin are essential for my site to run. So I am wondering, is there a way to conditionally load plugin based on page?

Question 1: Does conditionally load style sheet and script based on page help reducing the memory usage (NOT load time or Yslow score, but server memory usage)?
I know loading less style sheet and script increase the YSlow score. But I only care about Memory Usage for now. Is it worth an effort to conditionally load stylesheet and script?

Beside disabling plugins and/or conditionally load style / script, what other way to reduce memory usage?

I use Memory Viewers to check and it says "plugins_loaded" take 80mb. And the rest combined only take 10mb more. What the hell is the first plugins_loaded and why it takes so dang high memory? And how can I lower that number (and what contribute to that number?)

  • Tyler Postle

    Hey Hughred,

    Hope you're doing well today and thanks for your question!

    It looks like you have a few pretty heavy plugins there. I notice you have the p3 plugin performance tester too, which ones are taking up the most memory? Those are the ones you will want to look at trying to reduce :slight_smile:

    This plugin here is great for reducing html/css/js on your pages: https://wordpress.org/plugins/autoptimize/

    That should help.

    The size of your pages will be a factor here too if you're looking at page load times. For example, your home page is 10MB. Which is very large. Compare that to a site like Facebook who's homepage is only 1.2mb-ish or even Amazon which has a pretty graphic heavy homepage and it's less than 1mb.

    I can see on the gtmetrix test that your background video is a large part of this slow loadtime.

    The plugins_loaded is loading all the plugins you're using.

    Let us know which plugins are using the most memory, and also try out that optimize plugin!

    Look forward to hearing back hughred!

    All the best,
    Tyler

  • hughred22

    W3TC provide the same or better minified function I believe. And all my theme style is in SASS compressed and JS minified. So I do not need such plug-in to do it for me.
    My question is conditionally loading style and script based on page. Can this reduce my server memory usage?

    My home page is big is b/c the video. We are video company so the background video is needed...But even it take up 10MB, other still take up 90MB...

    Most of my plug-ins take up 10mb or so memory usage and I have a lot...and I need them all. I want alternative suggestion to reduce memory usage beside just disable plug-ins...

    Thanks!

  • Tyler Postle

    Hey Hughred,

    Thanks for your reply!

    Conditionally loading style and script based on page will reduce your memory usage, yes. However, it likely won't make too much of a difference for your memory usage or page load speed, on your home page anyway.

    Your memory usage could be hitting 80mb because you have 8 people loading your home page all at the same time for example. 10mb home page x 8 people loading it would get you to that 80mb already.

    Also, do you have other websites on your hosting account? If they are on the same server then they too would be adding to the memory usage of the server.

    Anyways, conditionally loading styles and script will help and here is a good "how to" on that as well in-case you need one: http://www.organizedthemes.com/loading-scripts-conditionally/

    Trying to reduce the size of your pages will help a lot, whether it's optimizing images, reducing video size, etc. this is because, say your home page is only 1mb then if 8 people load it simultaneously it is only using 8mb of server memory instead of 80mb.

    Hope that helps Hugh! Let us know if loading the styles/scripts conditionally helps :slight_smile:

    Talk to you soon.

    Cheers,
    Tyler

  • aristath

    Hello again @hughred22, I hope you're well today!

    Conditionally loading styles and scripts will not make much of a difference... the memory impact will be negligible.
    What you really need to do is optimize your server:
    1. Use nginx instead of apache.
    2. Use memcache & memcached
    3. Use a caching plugin.

    You could simply setup a VPS using this script: https://rtcamp.com/easyengine/
    This will setup your server and optimize it for WordPress using nginx, memcache, memcached, mysql, php-fpm, and everything else you need to run a WordPress-optimized script, all comfigured to perfection.

    I hope that helps!

    Cheers,
    Ari.

  • hughred22

    Thanks. But my server is NGINX (http://websynthesis.com/). And memcache & memcached is enable, and I use W3TC caching everything...

    But my problem is a same plug-in in my localhost only use 1mb memory and on my live server, it uses 4mb. So each plug-in use 4 time of the memory it supposed to be according to deBug bar...

    My website running for 2 years tho. Will that be a bad database? Any article or suggestion you can point me to further investigate this issue? Thank you!

  • Ajay

    Hi @hughred22, I hope you're well today!

    There are few tips , Hope can help

    * get cdn for video serve (less latency, better caching and that will serve video format as per screen request,
    as flv less size or mp4 for iphone etc.)
    * do not get load video autoload by default
    * use lazy loading pattern
    * can use load video thumbnail by default and on click thumbnail call the video via ajax load.
    * get database on another vps

    Analyze

    * p3 plugin performance tester
    * http://gtmetrix.com/ (this will tell which http call is taking time)
    * http://tools.pingdom.com/fpt/ (speed load with different country latency)

    Check your memory allocation to apc and memcache in config files,

    Hope above points will help you some way.

    Regards,
    Ajay Kwatra

  • Michelle Shull

    Hey there, hughred!

    I'm on websynthesis, too! They have a great support team over there. My production site, which is a heavy resource user, like yours, is running better on Synthesis than it has anywhere else, so I think you're on the right host.

    You could have some database overhead, have you tried optimizing it via plugin or through phpMyAdmin? DB overhead can be a huge lag on a site.

    Can you further optimize your background video? If not, Ajay's suggestion above of offloading your media files to a CDN is pretty smart. W3TC even has integration with Amazon AWS and a few other CDNs, it can automate a lot of the setup process.

    Which plugins are causing the most trouble? Can we maybe delay when any related scripts run for any of them?

    Thanks, Hugh! Hope you're well!

  • hughred22

    Thanks you Ajay and Michelle. I can use CDN to load the background video. It is only 2MB tho and only on the front page (so the memory impact will be negligible according to Ari). According to P3, the average memory usage is 120MB of my site. What is yours Michelle?
    Also Michelle, do you use New Relic inside W3TC to monitor your site performance? What is a good benchmark for a WordPress application performance according to New Relic?

    I optimize my database often in phpmyadmin. My database is 51MB with 20k overheat. After I optimized it 5 days ago. So this should be good.

    My site is pretty fast. I just worry about the memory usage. So if 1 visit use 100mb, and my plan of memory is 2G. So if 20 people visit my site at once, my site will crash, right?

  • Michelle Shull

    Heya, Hugh!

    I just looked, it's 92mb, *gulp.*

    I don't have New Relic, so I can't compare, there.

    Also, I'm pretty sure your site won't crash, you may be asked to chip in for a bigger plan, but even if you reach the upper limits of the memory allotted to you, I'm pretty sure you'll stay online. I think you'd probably get a dashboard warning, too.

    It sounds like you've already got a pretty solid plan in place to manage your site optimization. There's not much else, if anything, we could recommend that you're not already trying. If you're pushing your limits now, it may be time to upgrade to a bigger server.

    Thanks for your questions, and all the info provided here. : )

  • hughred22

    It is good to hear other websynthesis user here on WPMU. I will love to pick your brian a little more if I can. My goal is to bring it down to 100mb or so and it is pretty close after I disable BuddyPress (use UserPro instead) and deactivate some admin plug-ins. But my problem is, on a 0 plug-ins activated situation, my site is already take up 40MB...and websynthesis told me a normal installation is 7MB. That is 33MB different...

    They suggest and I quote "A default WordPress install on Synthesis usually doesn't go over 7MB in memory footprint, but I have seen a few going to 10MB. Keep in mind that even if you disable all your plugins, legacy data is still present at your database, which is why I would recommend a developer to take a look and optimize your website."

    Do you know what legacy data he is talking about? And do you know what a developer will usually do on optimize website on this level? I think I can do the same thing if someone can point me to the right direction and right article.

    BTW, I am going to start a new thread on New Relic. But it is very good on monitor performance. I know the Ruby standard. But on WordPress, I have no idea. You should try it too and you can find some really interesting data to help improve both front and back end performance. (And complaint to your host when thing get slow...)

  • Michelle Shull

    Howdy, Hugh!

    I do know what that legacy data is!

    Some plugins store key information in the database, with the intent of preserving it even if you delete the plugin, in case you want to install again.

    That's great, as long as you do want to install again, but it can create some overhead you don't want if you're not going to use that plugin any more.

    There are a few plugins that will let you delete orphaned database tables, but your best bet may be to take a look yourself and drop any tables you know you won't need again. (Take a db backup first, and make sure you're 100% confident that you don't need that table.)

    I will check out New Relic! You've inspired me. : )

    Have a great week, Hugh!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.