Skip to content

Commit 5a9a2aa

Browse files
authored
Update best-practices-asset-management.md
1 parent 93d973e commit 5a9a2aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/best-practices-asset-management.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# WordPress Asset Management Best Practices
22

3+
WordPress uses internal functions to register (`wp_register_script()` & `wp_register_style()`) and enqueue (`wp_enqueue_script()` & `wp-enqueue_style()` static JavaScript and CSS files so that WordPress Core, Themes and Plugins can **programatically interact with scripts and styles.**
4+
5+
This approach allows WordPress to:
6+
1. Load registered dependencies
7+
1. Chose the printing order & location of files in the DOM
8+
1. Print inline script/style alongside referenced files
9+
1. Print inline js variables preceeding scripts to make PHP data available to the script via the Window variable (`wp_localize_script()` -- originally used for "localizing" translation strings in scripts).
10+
311
#### Break `wp_register_script()` and `wp_register_style()` arguments onto their own lines
412

513
This is a matter of preference and judgement, but these registrations are super important, often overrun 80 characters and are worth breaking out to multiple lines for easy locating in files and nice code hygene.
@@ -56,3 +64,6 @@ Plus at time of writing it's 2017 and React and Vue-based apps, use of JavaScrip
5664

5765
#### Provide a version string for caching
5866
We recommend tying product assets the version for the Theme or Plugin you're in. Having a condition that checks for local environments (i.e. check request string for ".test") and toggling between a production version and `time()` is another good option for cache-busting on a local env.
67+
68+
###### NEW: Working with Assets containing cache-hash
69+
Often when working with JavaScript SPA frameworks and tools, a unique hash is generated in the filename. To account for these assets

0 commit comments

Comments
 (0)