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

[Bug]: Registers an unload listener #5913

Open
2 tasks done
GaurangMistry opened this issue Jan 11, 2024 · 22 comments
Open
2 tasks done

[Bug]: Registers an unload listener #5913

GaurangMistry opened this issue Jan 11, 2024 · 22 comments

Comments

@GaurangMistry
Copy link

GaurangMistry commented Jan 11, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

We have many sites in DNN and we are creating all sites perfectly with Google LightHouse. In Google LightHouse, we are facing one issue common in all sites is "Registers an unload listener". This is coming from Default Jquery file which DNN used.

I searched in google and got many suggestions to delete "Unload" from addEventListener method from Jquery or use "visibilitychange" but it's not work. We also take help of Jquery experts but not get expected result. So, we wish if you have any idea about it and you can directly work with us on project to fix this issue.

Steps to reproduce?

  1. Install Google Chrome Light House plugin
  2. Open website: https://www.shopsmart.website/ in Google Chrome
  3. Right-Click on website and select "Inspect".
  4. There is one option called "Lighthouse". Select it and click on "Analyze page load".
  5. Select "Best Practices" and you will get error for "Registers an unload listener".

Current Behavior

2024-01-10_16-09-04
2024-01-10_16-08-40
2024-01-10_16-07-58

Expected Behavior

Need to fix "Registers an unload listener" error and get 100% score in Google Lighthouse

Relevant log output

I searched in google and got many suggestions to delete "Unload" from addEventListener method from Jquery or use "visibilitychange" but it's not work. We also take help of Jquery experts but not get expected result.

Anything else?

No response

Affected Versions

9.13.0 (latest release)

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

Code of Conduct

  • I agree to follow this project's Code of Conduct
@valadas
Copy link
Contributor

valadas commented Jan 11, 2024

I am not sure if this is a DNN issue or not. If jQuery just does it, it is out of our purfiew. JQuery is not required in DNN for visitors, only for the edit experience (with the exception of popups being enabled and the Search skinobject).

We can't really troubleshoot from a production site with using the client resource management.

The current out-of-the-box theme does provide jQuery but the new theme in DNN10 will not. At any rate, your theme is not the out-of-box one so it is a moot point. But for now this is not really actionable unless there is reasons the believe this is DNN specific. For what its worth this error/warning is also present if you inspect github right here :)

If you have more details to make this issue actionable, please add info and I'll be happy to reopen.

@valadas valadas closed this as completed Jan 11, 2024
@uzmannazari
Copy link
Contributor

hello valadas i thinks this is not the issue for jquery or ajax. this is the problem that dnn used unload listeners on backend i think!
there is way to use beforeunload to fix this problem but i dont know how to change and where the functions used this

@uzmannazari
Copy link
Contributor

but this is the big problem that dnn websites are now have low rate of lighthouse because of this problem

@valadas
Copy link
Contributor

valadas commented Mar 13, 2024

From what I can see, it looks like a Microsoft.ajas issue and you already opened an issue there too MicrosoftDocs/feedback#3975

@valadas
Copy link
Contributor

valadas commented Mar 13, 2024

Searching the codebase here, I found this:

function Sys$WebForms$PageRequestManager$_onWindowUnload(evt) {
which may or may not be related

@valadas valadas reopened this Mar 14, 2024
@6TELOIV
Copy link

6TELOIV commented Mar 14, 2024

The unload handler is being set here:

Sys.UI.DomEvent.addHandler(window, "unload", this._unloadHandlerDelegate);

@6TELOIV
Copy link

6TELOIV commented Mar 14, 2024

It appears to be a MicrosoftAjax issue, but no idea where an appropriate place would be to open an issue with them.

@valadas
Copy link
Contributor

valadas commented Mar 14, 2024

Well, the link above is in DNN, I don't know off-the-cuff if it is the only instance, but it would be a start... I am not sure the error is on Microsoft side now with searching here...

@uzmannazari
Copy link
Contributor

as i see this is to replace the unload with beforeunload function but i dont know what will happen if we do that on dnn backend and whats the usage of this function !

@6TELOIV
Copy link

6TELOIV commented Mar 14, 2024

That could be something to try out and just see what happens; modify this line to say beforeunload instead of unload, though that probably won't work if the event actually needs to fire because beforeunload events won't run code.

I would recommend trying pagehide, or a more complex change would be visibilitychange because you'd have to check if the visibility is now "hidden" before firing their event. See this Google Dev article for more info.

@6TELOIV
Copy link

6TELOIV commented Mar 14, 2024

Another thing to try is just delete the line entirely and see what happens. It already doesn't fire reliably, and it will be gone for good eventually, so it would be good to see what happens if it just wasn't there at all.

@uzmannazari
Copy link
Contributor

i changed the MicrosoftAjax.js file yesterday but the scriptresource.axd file didnt changed!
i dont know how to change this ScriptResource.axd file and how this file is being created!

@valadas
Copy link
Contributor

valadas commented Mar 15, 2024

scriptresource.axd is a handler that can serve multiple scripts potentially merged together and/or minified, it is not a file exactly. What needs to be done is to see what is using onload, figure out the effects of changing it, etc.

@valadas
Copy link
Contributor

valadas commented Mar 15, 2024

Also, I spotted by a search one usage, but there could be more to it...

@uzmannazari
Copy link
Contributor

great @GaurangMistry
thanks for share this. but how can we set this condition on default.aspx file?

@uzmannazari
Copy link
Contributor

Untitled
i have this error when set this condition on default.aspx file

@valadas
Copy link
Contributor

valadas commented Mar 18, 2024

I don't think this is the proper fix. not using the offending method would be a better fix. The code is compiled into an assembly. There could be some workaround but the proper fix is to find the correct source of the bug.

@uzmannazari
Copy link
Contributor

I checked the @GaurangMistry website and now there is no error for unload listener on his website!

@uzmannazari
Copy link
Contributor

uzmannazari commented Mar 18, 2024

@valadas , this error on google lighthouse is not bug! it is about the standards that to be better on google websites need that.

We should not use unload listener in our codes

@valadas
Copy link
Contributor

valadas commented Mar 18, 2024

I agree, my point is that preventing the ajax library from loading is more of a workaround than a proper fix. I may have ramifications and the proper fix would be to fix the underlying code to not use unload.

@uzmannazari
Copy link
Contributor

your right mr valadas, now what should we do to fix this problem with lighthouse?
should we edit microsoft ajax js or dnn core?

@valadas
Copy link
Contributor

valadas commented Mar 25, 2024

I am not sure without spending the time looking into it. I think in DNN usage of microsoft Ajax potentially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants