-
Notifications
You must be signed in to change notification settings - Fork 69
Create Enqueued_Scripts_Size_Check #17
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
Comments
@jjgrainger The ACs here will need a bit of iteration since they are old and not based on our implementation of However, let's take a step back here first: Reviewing our
I think we need a way for check classes to express that they need certain reusable preparations. Maybe a new interface WDYT? We will need a few more issues about that, that should probably take precedence over the first runtime checks #17 and #19. |
Thanks @felixarntz I've created a new issue #59 to implement the interface for shared preparations. I'll update these AC's next week when I'm back. |
Hi @felixarntz I have updated the AC's and are ready for you to review. Thanks! |
@jjgrainger ACs mostly look good, however a few things are missing or need to be clarified:
|
Thanks @felixarntz I will update the AC's and dependencies. As this is dependent on #40 I have moved this to Sprint 5 where both issues will be worked on. cc @eclarke1 |
@jjgrainger ACs pretty much LGTM! One follow up item to consider though:
We should probably also consider dependencies of the script. For example, if a plugin enqueues a tiny script which depends on Maybe the dependency sizes could be stored in a separate variable so that the warning messaging can differ (e.g. "Your enqueued scripts use dependencies with a size of x" rather than "Your enqueued scripts have a size of x"). Since this is an additional effort and this issue is already quite substantial, we could also do this in a follow up issue though. WDYT? If you agree, please create that follow up issue, in that case the ACs here are good as is. |
Thanks @felixarntz I agree and have created a new issue for the follow up work - #74 |
@jjgrainger I'm assigning it to myself and starting on it as I'm waiting for the final review on the Admin Tools page ACs. Thanks! 🙂 |
Uh oh!
There was an error while loading. Please reload this page.
Description
Checks the number of scripts and the total size of all scripts registered in the plugin. This check will run the wp_enqueue_scripts action to register all plugin scripts. Using wp_scripts(), all scripts registered by the plugin will be looped over to get the size of the script along with any additional inline scripts. The number and total file size of all scripts will be calculated and then tested against the threshold, warning if either exceeds a threshold. Check should run relevant actions to make the data as accurate as possible as scripts can be registered and enqueued with any actions provided by WP like in the header or in the document body. Check should run through multiple contexts to make sure scripts enqueued by the plugin are covered in the analysis. Contexts could be any URLs from the site like the homepage, post types, templates, etc.
This issue is dependant on:
Acceptance Criteria
Enqueued_Scripts_Size_Check class
Enqueued_Scripts_Size_Check
should be created and exists atincludes/Checker/Checks
Enqueued_Scripts_Size_Check
should extend theAbstract_Runtime_Check
class.Enqueued_Scripts_Size_Check
will use theURL_Aware
trait.Enqueued_Scripts_Size_Check
will implement theWith_Shared_Preparations
interface.$threshold_size
property with a value of300000
.prepare()
method will be implemented in the class.$GLOBALS['wp_scripts'];
to a temporary variable.$GLOBALS['wp_scripts'];
to null if set.$GLOBALS['wp_scripts'];
value.get_shared_preparations()
method will be implemented.get_shared_preparations()
method will be used to return a preparation that creates a demo post for all publicly viewable post types using Create Demo_Posts_Creation_Preparation #40Demo_Post_Creation_Preparation
class name is an array key and it's value is an array of posts data to create, compatible withwp_insert_post
.get_urls()
method will be created.run( Check_Result $results )
should be implemented from theRuntime_Check
abstract class.run()
method will call therun_for_urls()
method passing an array of URLs returned by theget_urls()
method, a callable which will be the classescheck_url()
method, and theCheck_Results
instance.Check_Result $check_result
will be returned by therun
method.check_url()
method will be created.Check_Result
class and a URL string as parameters.$GLOBALS['wp_scripts'];
wp_enqueue_scripts()
to enqueue all of the checked plugins scripts.wp_scripts()
all enqueued scripts for the URL will be looped over:path
andsize
to a$plugin_scripts
array to be used as part of the results.$plugin_scripts_size
variable to be used as part of the results.$plugin_scripts_size
is checked agains the$threshold_size
$check_results
$plugin_scripts
is looped over an a warning message added for each.URL Aware Trait
URL_Aware
trait exists inincludes\Traits\URL_Aware
go_to( $url )
method that will simulate in WordPress the passed URL.go_to()
method will simulate the URL, similar to the WordPress Core test suite, by modifying the globalWP_Query
to match the URL passed.run_for_urls( array $urls, callable $callback )
go_to()
method.$callback
function passed for each of the URLs passing an instance of theCheck_Result
class and the URL as parameters.Tests Coverage
Enqueued_Scripts_Size_Check
class is expected to extendRuntime_Check
classEnqueued_Scripts_Size_Check
class is expected to be instance ofRuntime_Check
classrun
method expected to append the audit results to$check_result
The text was updated successfully, but these errors were encountered: