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
LazyLoad CSS Background Images #5987
Comments
To add this feature we will have to do the following parts:
UIFirst we will start by modifying UIs. The first one is on the settings page. On line 1097 we will have add a new section as following: 'container_class' => [
! empty( $disable_css_bg_img_lazyload ) ? 'wpr-isDisabled' : '',
'wpr-isParent',
],
'type' => 'checkbox',
'label' => __( 'Enable for CSS background images', 'rocket' ),
'section' => 'lazyload_section',
'page' => 'media',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
'input_attr' => [
'disabled' => ! empty( $disable_css_bg_img_lazyload ) ? 1 : 0,
], Then line 1023 we will have to add the following code to allow disabling the feature: $disable_css_bg_img_lazyload = (array) apply_filters( 'rocket_maybe_disable_css_bg_img_lazyload_helper', $disable_css_bg_img_lazyload );
$disable_css_bg_img_lazyload = $this->sanitize_and_format_list( $disable_css_bg_img_lazyload ); Finally we will have to change the description from the exclusion box line 1137 to "Specify keywords (e.g. image filename, CSS filename, CSS class, domain) from the image or iframe code to be excluded (one per line)"And add "background-image-style.css" to the placeholder line 1141: wp-rocket/inc/Engine/Admin/Settings/Page.php Line 1141 in 4819ee5
Then we will have to change the meta boxes. For that we will have to add a filter into Then inside the Admin subscriber from the lazyload bg css we will have the following logic: public function add_meta_box(array $fields) {
$fields['disable_css_bg_img_lazyload'] = __('LazyLoad CSS backgrounds', 'rocket');
} Business logicThen we will have to add the actual logic.
Inside the method maybe_replace_css_images we will have do the following actions:
Order between hooks needs to be handled by priority and the order should be the following one:
The parameter will have the following structure: [
'html' => 'content',
'css_files' => [
'url'
],
'css_inline' => [
'css',
],
'lazyloaded_images' => [
]'
] Extract CSSTo extract CSS we gonna base ourselves on the logic present inside the RUCSS:
Once this logic extracted we will then create a subscriber that will provide two method:
Both will be registered to the Create LazyTo extract the CSS we gonna use the
While parsing we need to check if the file already exists using the filesystem and skip the creation from the lazyfile and reuse the old one. Once parsed we will then create an array mapping the selector and the url value and we will swap the URL with its matching variable in the CSS file. Then we will save the CSS file into the filesystem using the Optimized filesystem and we will do the same for the array mapping the selector and the url that will be named same as the CSS file with Finally we will replace the name for each CSS file with the one of its new generated CSS file inside the HTML and do same for the inline CSS. Generating tagTo generate the tag we will use the lazyloaded mapping given by the $data that we will pass into Then we will use an class
FilesystemThe last part is the filesystem. As a class it will take two parameters:
The object should provide methods from the PSR-16 convention and rely on previously implemented function for its internal processing. To this we will add a method LoggerMost of the classes will have to use the Logger to simplify debugging. To reduce the workload to work with it we will use an inflector. To do this we will create an interface interface UseLoggerInterface {
public function set_logger(Logger $logger);
] And a trait trait UseLogger {
protected $logger;
public function set_logger(Logger $logger) {
$this->logger = $logger;
}
} Then we will have to create the inflector itself. For that we will create a service provider that we will load before every other one which gonna register the logger and the inflector inside its $container->add('logger', Logger::class');
$container
->inflector(UseLoggerInterface::class)
->invokeMethod('set_logger', ['logger']); |
We should be able to split this in at least 3 different sub-tasks |
Yes I told @piotrbak I first wait for you review then I gonna split it |
Is your feature request related to a problem? Please describe.
This is GitHub part of the new feature described here.
Additional context
Acceptance Criteria and all details are listed in the above link.
The text was updated successfully, but these errors were encountered: