-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sniff: WordPress.WP.EnqueuedResourceParameters
#170
Comments
I'd say no to the version parameter. There are other cache-busting techniques that theme authors use that work with their build tools, such as Laravel Mix. As for the in footer parameter, we can't make that call. Theme authors should determine where a script should be loaded. Both would make for good notices but not blockers. |
PHPCS can only throw errors and warnings, not notices. For the above mentioned sniff, we could make sure all messages thrown are warnings. The
The sniff will only throw a warning when the parameter isn't passed. If the parameter is passed, but explicitly set to
I'm not familiar with Laravel Mix, could you expand a bit on how that works in combination with registered/enqueue styles and scripts ? |
I can go into more detail when I get on my computer and share a code example. But, basically, Mix creates a manifest file for the script/style files with a |
Webpack has something similar. It appends hashes when bundling the assets, and you can use the webpack manifest plugin that will create Not what is used in the core and Gutenberg when using webpack, we could get some input from them as well. |
Laravel Mix is built on top of Webpack, so it probably does it in a similar way. Here's an example of an asset() function that I'm using. It basically pulls some JSON data that we'ved looked up and stored from a {
"/scripts/app.js": "/scripts/app.js?id=80419afdb240041e373e",
"/styles/screen.css": "/styles/screen.css?id=d41d8cd98f00b204e980",
"/styles/editor.css": "/styles/editor.css?id=d41d8cd98f00b204e980",
"/styles/customize-controls.css": "/styles/customize-controls.css?id=d41d8cd98f00b204e980",
"/scripts/customize-preview.js": "/scripts/customize-preview.js?id=5d7890f008eb42cfd35a",
"/scripts/customize-controls.js": "/scripts/customize-controls.js?id=a010549458e1f8dddc47"
} In the theme, whenever we want an asset, the When using the wp_enqueue_script( 'mythic-app', asset( 'scripts/app.js' ), null, null, true ); This is output on the front end as: <script type="text/javascript" src="http://localhost/wp-content/themes/abc/dist/scripts/app.js?id=80419afdb240041e373e"></script> |
Ok, so I understand the argument against the |
Warnings are fine but not errors. The goal here is to eventually have this tool as part of the theme submission process. Basically, anything I say is from that point of view -- should this block a theme from being submitted to the directory for review?
As far as I'm concerned, if it's used in 1 theme, we need to account for it. It's the validity of the use case that matters here. More and more theme authors are using build tools like this now. WordPress' Also, the example I pointed to above is from a starter theme that I'm going to be introducing to the community soon. It's my hope that many themes in the directory start using that method. |
@justintadlock Changing the error to a warning is not a problem at all. So the question basically is:
The second question looks to be answered, i.e. if it is included, it should be a warning, not an error. The first is still under discussion. As a side-note: I can imagine the Webpack/Laravel Mix argument can also be made for the sniff itself, so maybe an issue should be opened in WPCS suggesting lowering the error level to |
I think this has no place in this ruleset, not even as a warning. |
Care to explain why not? I'm fine with excluding this, due to the fact I'm working with webpack, but many people are not. |
I am up for checking |
I'm also fine with including it. It just needs to be a warning rather than an error. On the other hand, the sniff itself doesn't address the problem of keeping the version updated for cache busting. The theme authors who need this the most are likely the same theme authors who'll set it once and never update it. In that case, it's even more beneficial for it to not be set (at least it'll get the WP version and change on occasion). And, it's not something the review team is going to manually check. So, I do question the usefulness of having this in. |
Yes, what Justin said. Also, there is no requirement to tie it to. Also, there are plugins that remove the version numbers. And it doesn't apply to |
I think about 3rd party deps that get included frequently, so something like Bootstrap v4 should have
I agree with @joyously - I don't think warning/error would be necessary for any of the prefixed script handles, as the author could handle via a cache busting technique similar to what is outlined above, or leaving it out to use the fallback. I do however see validity in it being an error for thirdparty enqueued assets, which aren't prefixed. As far as real use case scenarios go, I recall seeing on multiple occasions theme and plugin issues which complain about fontawesome icons not working. It's usually not hard for the authors to sort it out, and the root cause is usually from the version strings not being added for the right resolution. Example: relying on fallback for WP 4.8 worked fine for a theme enqueuing FA 4.x, and a plugin enqueues FA 5.0.x. The user upgrades WP to 5.2.1, and now the theme's version of FA 4.x version is loaded and they are missing icons only in 5.0.x which were provided from the plugin initially. |
If this is kept as a warning, it shouldn't be used for the external fonts. |
We didn't reach a conclusion about adding this or not at the triage. I'm for including this with a warning notice, Joy is not. |
WPCS 1.0.0 added a new
WordPress.WP.EnqueuedResourceParameters
sniff which checks that when registering/enqueuing scripts and styles, a$version
is passed correctly so new versions will break out of the browser cache and for scripts, that the$in_footer
parameter is passed to prevent unnecessary layout-rendering blocking scripts.I would like to suggest adding this sniff to the TRTCS ruleset.
Opinions ?
Refs:
wp_enqueue_...
functions WordPress/WordPress-Coding-Standards#1146The text was updated successfully, but these errors were encountered: