Skip to content

Commit f2a240d

Browse files
authored
Update best-practices-asset-management.md
1 parent 7ae3654 commit f2a240d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

docs/best-practices-asset-management.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ This is a matter of preference and judgement, but these registrations are super
88

99
Always register CSS and JavaScript first instead of directly enqueueing them. This makes dequeueing easier for other products interacting with your dependency in the environment.
1010

11-
###### Additionally, always register assets globally. Never scope a script registration inside `is_admin()` or another check to prevent registration collision.
11+
###### Always register assets globally
1212

13-
#### Store dependency handles in accessible variables and constants
13+
Never scope a script registration inside `is_admin()` or another check to prevent registration collision.
1414

15-
When registering CSS or JS within a PHP class, always store the asset handle as a class variable. When registering a dependency outside a class, define a PHP constant. This allows the entire class and application interact programmatically with the asset, preventing string scavenger hunts across files and easing rename.
15+
#### Store the string used to register/enqueue an asset in a static class variable or PHP constant
16+
17+
This allows the entire class and application interact programmatically with the asset, preventing string scavenger hunts across files and easing rename.
1618

1719
#### Naming dependency handle slugs
1820
* **This is a global namespace**. Be creative, be courteous, be concise, be clear and be defensive.
19-
* Please don't describe the asset with a postfix like `-js`, `-css`, `-script`, `-style` -- WordPress will add postfixes when printing assets in the DOM, resulting in `something-js-js`. However, if a product is called purecss or momentjs, we then use the full slug with repetitive postfix, despite repetion (i.e. `purecss-css`)
20-
* When appropriate, try to match the filename. This makes life easier and applications scale nicer.
21+
* **Please don't use a postfix like `-js`, `-css`, `-script`, `-style`** -- WordPress will add postfixes when printing assets in the DOM, resulting in `something-js-js`. However, if a product is called purecss or momentjs, we then use the full slug with repetitive postfix, despite repetion (i.e. `purecss-css`)
22+
* **Try to keep parity between filename and dependency string**. This makes life easier and applications scale nicer.
23+
* **Plan for growth: avoid calling dependency "my-product.ext."** Use `-primary`, `-core` or `-main` prefix.
2124
* Never use WordPress Filters or difficult-to-predict dynamic variables to register asset handles so others may dequeue and register handles with confidence.
2225

2326
#### Leverage dependency chaining and the `array()` method for `wp_enqueue_*()`

0 commit comments

Comments
 (0)