Host Google Analytics Locally

CAOS (Complete Analytics Optimization Suite) for Google Analytics allows you to host analytics.js/gtag.js/ga.js locally and keep it updated using WordPress’ built-in Cron-schedule. Fully automatic!

Whenever you run an analysis of your website on Google Pagespeed InsightsPingdom or GTMetrix, it’ll tell you to leverage browser cachewhen you’re using Google Analytics. Because Google has set the cache expiry time to 2 hours. This plugin will get you a higher score on Pagespeed and Pingdom and make your website load faster, because the user’s browser doesn’t have to make a roundtrip to download the file from Google’s external server.

Just install the plugin, enter your Tracking-ID and the plugin adds the necessary Tracking Code for Google Analytics to the header (or footer) of your theme, downloads and saves the analytics.js/ga.js/gtag.js-file to your website’s server and keeps it updated (automagically) using a scheduled script in wp_cron(). CAOS is a set and forget plugin.

Please keep in mind that, although I try to make the configuration of this plugin as easy as possible, the concept of locally hosting a file or optimizing Google Analytics for Pagespeed Insights or GT Metrix has proven to be confusing for some people. If you’re not sure of what your doing, please consult a SEO expert or Webdeveloper to help you with the configuration and optimization of your WordPress blog. Or feel free to contact me for a quote.

For more information: How to setup CAOS.

Google PageSpeed Insights – Scoring 100/100 with WordPress

Font Awesome#

Many people who use Font Awesome take the CSS file and place it in their header. The problem is that if you put this into your header, it becomes render-blocking as CSS is render-blocking. Instead, we take the following code and we move it down to our footer, right before the </body> tag.

<span class="token tag"><span class="token punctuation"><</span>link <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/fontawesome.min.css<span class="token punctuation">"</span></span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>stylesheet<span class="token punctuation">"</span></span><span class="token punctuation">>


</span></span>

Note: Doing this will result in FOUT, which is a flash of unstyled text.

Google Fonts#
ppagespeed insights google fonts

The third issue is with our Google Fonts. By default, WordPress uses a hook called wp_enqueue_scripts that loads the font in your header. This automatically results in it becoming render-blocking. To fix this we install a free plugin called Disable Google Fonts. If you are using a custom theme this may vary slightly, or you can ask your theme developer how to disable Google Fonts.

We then include our Google Font with the following code in our footer, right before the </body> tag.

<span class="token tag"><span class="token punctuation"><</span>link <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">'</span>https://fonts.googleapis.com/css?family=Noto+Serif:400,400italic,700,700italic<span class="token punctuation">'</span></span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">'</span>stylesheet<span class="token punctuation">'</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">'</span>text/css<span class="token punctuation">'</span></span><span class="token punctuation">></span></span>

Note: Doing this will result in FOIT, which is a flash of invisible text.

You could also load your Google Fonts asynchronously by using Google’s Web Font Loader. Simply place the following code below in your footer.

<span class="token operator"><</span>script type<span class="token operator">=</span><span class="token string">"text/javascript"</span><span class="token operator">></span>
    WebFontConfig <span class="token operator">=</span> <span class="token punctuation">{</span>
        google<span class="token punctuation">:</span> <span class="token punctuation">{</span> families<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">'Noto+Serif:400,400italic,700,700italic'</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">var</span> wf <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">'script'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        wf<span class="token punctuation">.</span>src <span class="token operator">=</span> <span class="token string">'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'</span><span class="token punctuation">;</span>
        wf<span class="token punctuation">.</span>type <span class="token operator">=</span> <span class="token string">'text/javascript'</span><span class="token punctuation">;</span>
        wf<span class="token punctuation">.</span><span class="token keyword">async</span> <span class="token operator">=</span> <span class="token string">'true'</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> s <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementsByTagName</span><span class="token punctuation">(</span><span class="token string">'script'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        s<span class="token punctuation">.</span>parentNode<span class="token punctuation">.</span><span class="token function">insertBefore</span><span class="token punctuation">(</span>wf<span class="token punctuation">,</span> s<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token operator"><</span><span class="token operator">/</span>script<span class="token operator">></span>
pagespeed insights no render-blocking

How to enable HTTP/2 support in Apache

Ubuntu / Debain

Apache web server distributed in default software repositories of Ubuntu and Debian do not include mod_http2 needed to enable HTTP/2 functionality. You will need to add a third-party package source with latest Apache version that also inludes mod_http2.

    apt-get install software-properties-common python-software-properties
    add-apt-repository ppa:ondrej/apache2
    apt-get update

This will install some utilities (if not installed already) that help us add external PPAs. Secondly, we add the ondrej/apache2 PPA which contains the latest Apache2 builds. Third, we update your systems package information.

    apt-get install apache2
    apachectl -v

This is to upgrade your existing Apache2 version to the latest version. After upgrading, the apachectl -v command will reveal your upgraded Apache version. This will be 2.4.29 or later.

Enable HTTP/2 module

Apache’s HTTP/2 support comes from the mod_http2 module. Enable it from:

a2enmod http2
  apachectl restart

Add HTTP/2 Support

We highly recommend you enable HTTPS support for your web site first. Most web browser simply do not support HTTP/2 over plain text. Besides, there are no excuses to not use HTTPS anymore. HTTP/2 can be enabled site-by-site basis. Locate your web site's Apache virtual host configuration file, and add the following right after the opening <VirtualHost> tag:
  Protocols h2 http/1.1
Overall, your configuration file should look something like this:
<VirtualHost *:443>
  Protocols h2 http/1.1
  ServerAdmin you@your-awesome-site.com
  ServerName your-awesome-site.com
  ...
</VirtualHost>
After the changes, don't forget to reload/restart Apache.
apachectl restart

Push resources

Apache supports HTTP/2 Push feature as well. After enabling Apache HTTP/2, you can add push support simply by setting HTTP Link headers. You can emit them from either/both the Apache configuration file, or from your application.
  Link: </assets/styles.css>;rel=preload, </assets/scripts.css>; rel=preload
Above is an example header that would trigger Apache to push the /assets/styles.css and /assets/scripts.scc files. Refer to your application code on how to emit HTTP headers. If you would like to make Apache add these headers, you can do so like this, using the mod_headers module.
<Location /index.htmll>
  Header add Link "</assets/styles.css>;rel=preload, </assets/scripts.css>; rel=preload"
  Header add Link "</assets/image.jpg>;rel=preload" 

Apache 2.4.27, HTTP/2 not supported in prefork

Starting from Apache 2.4.27, the Apache MPM (Multi-Processing Module) prefork no longer supports HTTP/2. This will be indicated in your Apache error log as follows:
AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
To fix this, select a different MPM: event or worker. We highly recommend you to use the event prefork.
If you are using PHP, it is likely that PHP is integrated to Apache via the mod_php module, which requires the prefork MPM. If you switch out from preform MPM, you will need to use PHP as FastCGI. To switch to php-fpm, you can do as folllwing. Please note that this assumes you have PHP installed from ondrej/php repository on Ubuntu. The PHP package names could be different in other repositories. Change package name and apt-get commands to match your PHP vendor and package manager.
    apachectl stop
    apt-get install php7.1-fpm # Install the php-fpm from your PHP repository. This package name depends on the vendor.
    a2enmod proxy_fcgi setenvif
    a2enconf php7.1-fpm # Again, this depends on your PHP vendor.
    a2dismod php7.1 # This disables mod_php.
    a2dismod mpm_prefork # This disables the prefork MPM. Only one MPM can run at a time.
    a2enmod mpm_event # Enable event MPM. You could also enable mpm_worker.
    apachectl start

HTTP/2 not enabled on older TLS versions

Mozilla Firefox (among other browsers) does not enable HTTP/2 protocol unless the connection is made over TLS 1.2 and using modern cipher suits. This is not a technical limitation, but rather a safety precaution. Make sure your that your site supports TLS 1.2, and modern cipher suits with AES/CHACHA20 with forward-secrecy key exchanges. In turn, Apache does not try to establish an HTTP/2 connection with connections over older cipher configurations either. you can force Apache attempt HTTP/2 upgrade with the following directive, but it will not be as effective because browsers do not support HTTP/2 from their end anyway.
    H2ModernTLSOnly off

What is Redis Object Caching and How to Use It for Your WordPress Site

Redis and object caching can vastly speed up your WordPress page load times with each subsequent visit. It’s also used by many popular websites like GitHub, Pinterest, StackOverflow and many others.

Remote Dictionary Server (Redis) “is an open source, in-memory data structure store used as a database, cache, and message broker.” It’s a key-value store which is often called a NoSQL database.

It’s best used on dynamic websites such as WordPress sites when it comes to object caching, which caches repeating query results.

Today, I’ll share more detail on object caching, its benefits, and how to install and use Redis for object caching on WordPress websites.

 

More: kinsta.com

Plugin: redis-cache

GitHub WordPress Plugin: