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
- Loading the theme’s minified
style.cssfile when not in development mode
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.
Your best friend is code, Tonya is making the introductions.
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
In Part 2 of the Better Asset Versioning series, let's dive into how to remove the query strings, i.e. the ?ver=1.0.0 from the static resources. Static resources are the scripts, fonts, styles that we enqueue. When you run speed tests on sites like Pingdom, a common ding to the performance score is this very topic. Let's build a plugin that removes the query string and places it inline as part of the static URL.
Check out the WordPress Fundamentals Library for more hands-on labs, insights, Docx, and more.
Check out the series page for more labs: Better Resource (Asset) Versioning Series