Load first page faster

General questions about CMSimple
bca
Posts: 269
Joined: Tue Sep 15, 2009 4:49 pm

Re: Load first page faster

Postby bca » Sat May 28, 2016 4:47 pm

I put statcounter in as a test ages ago and completely forgot about it. i have removed it now. Is it quicker now? Dont know. :P

With regard to your little mod above...I assume i am meant to see the cached file in the cmsimple/cache folder.
Nothing seems to be in there. I have set permissions to 777

b

meltemi
Posts: 134
Joined: Sat Feb 22, 2014 10:11 pm
Location: Franken (Deutschland)
Contact:

Re: Load first page faster

Postby meltemi » Sat May 28, 2016 11:36 pm

bca wrote:you tested the original page

Yes. Because I think, the problem has to be solved there. (If you prefer hand made pages, you don't need any CMS.)

But the comparison on gtmetrix is interesting (just checked):
original home page (first line in waterfall): 1,09s, re-tested: 1,16s
hand made index.html (first line in waterfall): 313ms, re-tested: 319ms

bca wrote:As Google is the one that is important I was following their guidelines on Google pagespeed insights [...] I am getting a score of 99/100 with the html page.

Do you want fast pages for your users or a nice score for yourself? A page with 8 requests and 80 KB and a score of 60 will always load faster than a page with 60 requests and 2000 KB (despite a Google Page Speed score of 100). The number of requests and the memory need are no criterions for Google Page Speed. But they might be criterions for Google Search Engine.

cmb wrote:[1] That might be the statcounter.

No, statcounter does not start sessions on user pages. But 20 months ago the 1981 date was in the response header of cmsimple-xh.org (discussed here).

cmb
Posts: 11689
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Load first page faster

Postby cmb » Sun May 29, 2016 10:25 am

bca wrote:I put statcounter in as a test ages ago and completely forgot about it. i have removed it now. Is it quicker now? Dont know. :P

I can't tell. The page didn't took that long to load while the statcounter was in place, at least for me. Now it takes about 2 secs for me.

bca wrote:With regard to your little mod above...I assume i am meant to see the cached file in the cmsimple/cache folder.
Nothing seems to be in there. I have set permissions to 777

Indeed, the cached pages are supposed to be in cmsimple/cache/. I don't know why that doesn't work. But as Holger and meltemi said, it's probably best to fix the root cause of the slow page speed.

meltemi wrote:
cmb wrote:[1] That might be the statcounter.

No, statcounter does not start sessions on user pages. But 20 months ago the 1981 date was in the response header of cmsimple-xh.org (discussed here).

Yes, I know. The issue was that there was a bug, which caused a session to be started for all accesses (not only in admin mode). That bug is supposed to have been fixed in the meantime.

Anyhow, even though statcounter has been removed in the meantime, the session is still opened. So that might be caused by a plugin, perhaps Countall.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

meltemi
Posts: 134
Joined: Sat Feb 22, 2014 10:11 pm
Location: Franken (Deutschland)
Contact:

Re: Load first page faster

Postby meltemi » Mon May 30, 2016 12:08 am

I have checked some websites (always the home page) on the same IP (94.126.40.42) by Chromium 49 developer tools (out of Opera 36): Network -> document -> time:

Code: Select all

cordeo.org.uk              2.98 s     CMS: Wordpress
poundsterlingforecast.com  2.81 s     CMS: Wordpress
mypockets.co.uk            2.47 s     CMS: Wordpress
jemmebali.com              1.61 s     CMS: Wordpress
plocktoninn.co.uk            966 ms   CMS: Wordpress
playcasters.com              900 ms   CMS: Wordpress
uk-sites.com                 179 ms   hand made, without PHP
cridler.com                  154 ms   hand made, without PHP

Numbers of domains hosted on 94.126.40.42: about 2,392 :-( Too many.

@bca,
in your place I would change the isp. Before change: check the speed of some websites hosted with the new isp. More than one second for the document is bad. Less than 500 ms is ok, less than 300 ms is more ok.

bca
Posts: 269
Joined: Tue Sep 15, 2009 4:49 pm

Re: Load first page faster

Postby bca » Tue May 31, 2016 2:49 pm

It is not an option to change the isp at the moment. The only solution from them is for me to buy a dedicated server so its not shared.

However Google does agree with you
PageSpeed Insights only considers the network-independent aspects of page performance: the server configuration, the HTML structure of a page, and its use of external resources such as images, JavaScript, and CSS. Implementing the suggestions should improve the relative performance of the page. However, the absolute performance of the page will still be dependent upon a user’s network connection.

As its my intention to get on the first page of Google for most relevant searches I feel I need to bend over backwards to do what Google wants me to do to make my site perfect for their criteria :cry:

I managed to get your mod to work Christoph. Line number 1554 is not right (at least not on my functions.php)
I do see a better response as shown by both GTMetrix and Google pagespeed. Not as good as a completely hand written html first page but still a lot better.

Is this a plugin you might pursue?

B

cmb
Posts: 11689
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Load first page faster

Postby cmb » Tue May 31, 2016 5:36 pm

bca wrote:I do see a better response as shown by both GTMetrix and Google pagespeed. Not as good as a completely hand written html first page but still a lot better.

Great! Thanks for testing. Consider to use the updated code for now (for security reasons mentioned by Holger).

bca wrote:Is this a plugin you might pursue?

Actually, that would make sense, especially as I had developed a draft of a client-side caching plugin a while ago. I don't know if I'll find the time, though.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

bca
Posts: 269
Joined: Tue Sep 15, 2009 4:49 pm

Re: Load first page faster

Postby bca » Fri Jun 10, 2016 11:30 am

This might be a silly question but as the various plugins' css files are all joined together to form plugins.css why don't we also join the core.css and the template's css so only one css file needs to be retrieved?

Surely the same function can do it?

B

cmb
Posts: 11689
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Load first page faster

Postby cmb » Fri Jun 10, 2016 1:23 pm

bca wrote:This might be a silly question but as the various plugins' css files are all joined together to form plugins.css why don't we also join the core.css and the template's css so only one css file needs to be retrieved?

Well, there may be several page (and language specific) templates involved, what has to be catered to. core.css is always the same, but as the order of CSS rules matter, we can't simply combine core.css with plugins.css. It would be possible to add a config option ("use only 1 template") and to join all three stylesheets if the option is enabled, but that might cause confusion, if the option is set, but later the webmaster is trying to use a page specific template. It might be reasonable to check whether there are actually page or language specific templates involved, but that requires further investigation (might slow down the system unless some further optimizations are done). And it might be an alternative to have mutiple combined stylesheets depending on the actual template – off the top of my head that appears to be the best solution – but that requires some decisions (for instance, where to store the combined stylesheets[1]) and might cause some issue. Further investigation would be needed.

Anyhow, I've put it on the CMSimple_XH 1.7 roadmap.

See also the original discussion on Joining Plugin Stylesheets.

[1] Storing in the same place as plugins.css now, would leave unused files if a template is uninstalled. Storing in the template folder might have other drawbacks.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

cmss
Posts: 53
Joined: Mon Jan 02, 2017 6:15 pm

Re: Load first page faster

Postby cmss » Tue Mar 28, 2017 7:57 pm

cmb wrote:
cmb wrote:However, I would prefer a more general solution, namely a server side caching of the generated pages. […] Nonetheless, an approach that might be more carefully investigated.

I've quickly put together a first draft. Place the following in the newly created file cmsimple/userprelude.php:

Code: Select all

<?php

if 
(!preg_match('/index\.php(?:\?|$)/', $_SERVER['REQUEST_URI'])
    && in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'))) {
    // cache();
    // for security reasons we only cache the start page for now:
    if ($_SERVER['QUERY_STRING'] === '') {
        cache();
    }
}

function cache()
{
    global $cachefilename;

    $cache = __DIR__ . '/cache/';
    if (!file_exists($cache)) {
        mkdir($cache, 0777);
        chmod($cache, 0777);
    }
    $filename = $cache . md5("$cache{$_SERVER['QUERY_STRING']}") . '.html';
    if (file_exists($filename)) {
        readfile($filename);
        exit;
    } else {
        $cachefilename = $filename;
    }

Insert the following code fragment in XH_finalCleanUp() line 1554:

Code: Select all

    global $cachefilename;

    if (!XH_ADM && isset($cachefilename)) {
        file_put_contents($cachefilename, $html);
    

After these modifications responses to each GET (and HEAD) request will be cached in cmsimple/cache/ (if the folder is not created automatically, do it manually and set write permissions (0777), and if already cached will be delivered from the cache. To be able to administrate the site, you explicitly have to request /domain-root/index.php. After each modification to the page cmsimple/cache/ has to be emptied manually (that could be automated for each logout, though).

In my local development environment that gave a nice performance boost (access via index.php, i.e. without caching, took roughly 700 ms, access to already cached pages took around 200 ms).

Warning: for security reasons the code should not be used on a production server. As far as I can see, there are no issues (but, of course, I could be wrong) – at least if there are no protected pages (Memberpages/Register) involved, which would loose their protection!


------------------------------------------------------------------------------------------------------
The above method has a conflict with the cache-dev-plugin which is much faster : Fatal error: Cannot redeclare cache() (previously declared in /home/www/web724/html/upfad/cmsimple/userprelude.php:14)

cmb
Posts: 11689
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Load first page faster

Postby cmb » Mon Apr 03, 2017 6:01 pm

cmss wrote:The above method has a conflict with the cache-dev-plugin which is much faster

Which cache-dev-plugin?
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+


Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest