wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

3.16 - Beacon script implementation

Open Miraeld opened this issue 1 year ago • 2 comments

Context

As a user, I want WP Rocket to analyse and store LCP/ATF information of my pages so that those images can then be optimised. This issue has the goal to develop the green part of this diagram: Untitled

Must be done after #6430 so that it can be tested

Scope a solution

  • To implement this, we need to create the beacon script in javascript that will run on pages to collect images.
  • A prototype of the script can be found here.
  • The script can be created and placed here.

The script needs to collect images of the page, and save them within the database through an AJAX call.

If the script encounter an error, we should save it to the DB as well.

  • Add a new Subdir AJAX with a controller and a subscriber
  • The subscriber will have an event wp_ajax_rocket_lcp, with a callback add_lcp_data()
  • The method will call the same named method in the controller
  • This method will update the DB based on the result of the script (failed, error, no image, success), while performing security checks
  • The controller will need to have a dependency with the DB query class to write in the table
  • Add tests

Acceptance Criteria

  • Data is added to the DB once the AJAX call is made

Effort estimation:

Effort [M]

Miraeld avatar Feb 05 '24 08:02 Miraeld

Some work is needed here on AC, to check with @Mai-Saad's suggestion:

can be: save optimized images (all types mentioned above) to the database, if any error occurs i.e timeout, …etc, save the error in the database and start retries up to 3 then fail if the error is still there

MathieuLamiot avatar Feb 07 '24 13:02 MathieuLamiot

This issue includes security checks like SQL injection and payload size to avoid to big DB footprint.

MathieuLamiot avatar Feb 07 '24 16:02 MathieuLamiot

smoke test is good here (security, different markups and error cases will be on different GH) testrail-report-592.pdf

Mai-Saad avatar Apr 17 '24 17:04 Mai-Saad