litespeedtech / litespeedtech/lscache_wp

fix js delayed bug for load event

Open
#629 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
257
Forks
123
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/litespeedtech/lscache_wp/assets/54323929/1e32278a-5020-4b2c-a354-652531b1533f)

i try this code and it's fix the problem
```php
/**
* 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue points to the litespeed_optm_cssjs filter and delayed JavaScript handling; start by locating that filter and the commented load-event replacement. Reproduce a script that depends on the load event, then verify the delayed script receives the intended event without breaking the existing DOMContentLiteSpeedLoaded behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php, wordpress
Domain
performance, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.