Let’s plan out our plugin. There are multiple features and considerations that we need to think about before we start writing code.
In this episode, we will talk about the strategy of reducing redundant code and how to architect a custom site. We talk about why using the same file embedded into each theme and plugin can increase your costs, risks, and time.
Then we’ll talk about the different tasks that this plugin will do, including:
- Move the versioning utility file out of the theme, i.e. that we built in Part 1, and put it into our new plugin.
- Strip off the version number query string and move it into the filename.
- Add the rewrite rule for Apache in
.htaccessand configuration file for Nginx.
- Deal with assets that already have the version number as part of the static URL.
- External assets.
- Configurable way to skip certain assets.
This plugin is changing the static URL. The path to the asset file does not exist. Why? We will change the filename by adding the version number between the filename and the extension. I show that to you in the episode.
Therefore, we have to add a rewrite rule for the web server to know how to route to the physical file on the server’s hard drive.
Building it in OOP
You will build this plugin in OOP. However, I’m not teaching you OOP in this lab. Therefore, if you want to know more about OOP, go do this lab:
If you prefer not to build this plugin, but rather you just want to use it, you can download it off of GitHub.
Code. Eat. Code. Sleep. Dream about Code. Code.
Total Lab Runtime: 03:18:22
- 1 Lab Introductionfree 09:30
- 2 What is a URL Query String?free 14:36
- 3 The Intent of ?ver=1.0.0free 12:22
- 4 Understanding the Problemfree 14:01
- 5 Cache Busting Strategiesfree 09:57
- 6 Planning Our Pluginpro 18:17
- 7 Versioning Utility Helper Filepro 08:36
- 8 Start the URL Converter Classpro 18:11
- 9 Hook into WordPresspro 11:57
- 10 Regex or Parse the URL?pro 12:30
- 11 Convert with Regexpro 06:10
- 12 Apache and Nginx Rewrite Rulespro 10:43
- 13 Deciding Whether to Convertpro 07:35
- 14 Skip When No Version Query Stringpro 09:18
- 15 Only the Local Assetspro 14:09
- 16 Improving Our Code & Readabilitypro 11:52
- 17 Test, Fine-Tune, and Wrap it Uppro 08:38