Skip to content
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

fix js delayed bug for load event #629

Open
AkramiPro opened this issue Mar 13, 2024 · 0 comments
Open

fix js delayed bug for load event #629

AkramiPro opened this issue Mar 13, 2024 · 0 comments

Comments

@AkramiPro
Copy link
Contributor

AkramiPro commented Mar 13, 2024

i notice that you replace DOMContentLoaded with DOMContentLiteSpeedLoaded
but not for load event
so some codes not runnig that depend on "load" event
i check and see that you try to fix this issue but it's commented for now:
image

i try this code and it's fix the problem

/**
 * fix delay js load bug for "load" events
 */
add_filter( 'litespeed_optm_cssjs', function ( $con, $file_type, $src ) {
    if ( $file_type === 'js' ) {
        $con = str_replace( 'addEventListener("load"', 'addEventListener("DOMContentLiteSpeedLoaded"', $con );
    }

    return trim( $con );
}, 9999, 3 );

Update:
i know that load and DOMContentLoaded has small difference in logic but in case we want to delay load all js it is not matter to use DOMContentLoaded instead of load event. so replace it with DOMContentLiteSpeedLoaded does not make a problem (i think). in my test everything is works fine

@AkramiPro AkramiPro changed the title fix js delayd bug for load event fix js delayed bug for load event Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant