In Part 1 of the Better Asset Versioning, we are looking at the version number that is applied to each asset resource, i.e. our scripts, fonts, and stylesheets. We are highly inefficient with this process. Let’s eliminate the hard coding of version numbers when we enqueue. Let’s build a better strategy for version numbers when in development mode. Let’s automate versioning and improve our build process.
This hands-on lab is part 1 of the Better Asset Versioning series. In this part, you are learning all about versioning and then building code to automate it. Then in part 2 we go further to eliminate the query string from our static asset URLs.
This lab will increase your productivity when you are building and testing. It will eliminate the frustration of busting through the browser’s cache, especially when you are building or demoing to our client.
The strategies you’ll explore and the code you’ll build work with ANY THEME or PLUGIN.
What You Will Learn
This lab is packed full of WordPress, HTML, and PHP goodness. You’ll learn:
- Why we need versioning
- Defining a version numbering scheme that you can use
- Eliminating the need to hard code the version number in the theme and plugins when enqueuing scripts and styles (Psst, you will forget to change them when you make changes to the file.)
- Leveraging the asset file’s modification time to stop hard coding version numbers
- Our development needs vs. released product/website needs
- Extracting the version number from the theme’s
style.css
file…automatically - Loading the theme’s minified
style.css
file when not in development mode - PHP
filemtime
Getting Setup to Do the Lab
Let’s get you setup to do this lab.
You need to have a sandbox test site spun up and ready to go. If you need help with that, see the Setting Up Your Sandbox Test Website article in our Help Center. Make sure you turn on the debug mode in your wp-config.php
file. The code is in that same Help Center article.
We will be using the Twenty Seventeen theme. And if you work with Genesis, we’ll also work with the free Genesis Sample child theme.
Prerequisites
There’s a time to code and …. yup, that sums it up.
Episodes
Total Lab Runtime: 02:27:07
- 1 Lab Introductionfree 11:19
- 2 Why is Version Number Necessary?free 16:30
- 3 Version Numbering Schemepro 06:47
- 4 Forget Hard Coding Version Numberpro 15:02
- 5 Forget Hard Coding - Grab Stylesheet's Versionpro 05:19
- 6 Forget Hard Coding - Genesispro 05:17
- 7 Load the Theme's Minified Stylesheetpro 10:23
- 8 Strategy Session: Minified or Full for Theme Versionpro 12:25
- 9 Load the Minified Stylesheet in Genesispro 05:04
- 10 Refactor to Improve Our Codepro 11:20
- 11 Applying It to Scriptspro 18:14
- 12 Apply it to Scripts - Genesispro 09:13
- 13 Convert into Utility File - for Reusepro 14:30
- 14 Wrap it Upfree 05:44