MonthJuly 2020

WordPress optimization that works easily and safely.

I see lots of new WP users trying to optimize their sites using the most advanced plugins and methods, DONT!. Most of the times you end up destroying your site and spend many hours debugging. The following plugins will help you without needing to change their default settings or read tutorials.

  • No 1 thing to keep in mind is to clear your cache regularly to actually see what your visitors see. Using a browser with empty cache just for that is the easiest way.
  • No 2 , if you use a bloated theme and 100 plugins no need to go the extra mile to optimize your site, it is not possible.

WP Super Cache, really easy to use without having to change the defaults. Plenty of documentation and tutorials. Works with WooCommerce and if you have a good host you can enable the ‘expert’ mode.

Autoptimize, use it for HTML, CSS, JS and images.

Redis Object Cache, caches your database queries, unfortunately you need a good hosting company to support it and it can cause trouble some times 🙂

Sticky FacetWP flyout menu

To make it sticky I used the offsetParent, offsetTop and scrollY properties. I placed the button in a positioned element ( not sticky ) hid it with opacity so I can animate it and get the offsetParent ( does not work with display:none; ) and then used scrollY to change it’s opacity. I added a class ‘.sticky-facetwp’ to the button to target it.

The CSS

button.sticky-facetwp {
	opacity: 0;
	position: absolute;
	z-index: 99;
	color:#000 !important;
	transition-property: opacity;
	transition-duration: 1s;
	transition-delay: 0s;
}

.archive button.fixed-sticky-facetwp {
	opacity: 1;
	position: fixed;
}	

The JS


const page = document.querySelector('#content')

// get the filter button
const theFilter = document.querySelector('.sticky-facetwp')
const theFilterTop = theFilter.offsetTop

function stickyfacetwp() {
	if (window.scrollY >= theFilterTop) {
        theFilter.classList.add('fixed-sticky-facetwp');
      } else {
        theFilter.classList.remove('fixed-sticky-facetwp');
      }
}

window.addEventListener('scroll', stickyfacetwp)

offsetHeight of image equals zero

Scripts without async , defer or type="module" attributes, as well as inline scripts, are fetched and executed immediately, before the browser continues to parse the page.

To get the offsetHeight when using an inline script you can use an event listener like

window.addEventListener(‘load’, start);

load to wait for all assets OR link the script with ‘src’

<script src=”app.js”></script>

to load it after the assets loaded.