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

Recent commit causes issue with external and inline scripts #502

Closed
tremby opened this issue Mar 13, 2015 · 6 comments
Closed

Recent commit causes issue with external and inline scripts #502

tremby opened this issue Mar 13, 2015 · 6 comments
Labels

Comments

@tremby
Copy link

tremby commented Mar 13, 2015

Commit 0019136 introduces an issue on a site I'm working on.

I'm using the PHP debug bar, which injects some code at the end of the body tag of the page. The code includes an external script (jquery, in case you didn't already have it loaded, and whatever code it needs to run) and then an inline one (jQuery.noConflict(true)).

When pjax does its thing, the external one is skipped but the inline one runs. This has the effect of knocking out my instance of jquery, and then my page breaks.

This is most likely PHP debug bar's bug (I imagine noConflict could be included in the external script, and then we wouldn't have this problem), but I wanted to flag it in case it's a case you hadn't considered.

@mislav
Copy link
Collaborator

mislav commented Mar 13, 2015

When pjax does its thing, the external one is skipped but the inline one runs.

What exactly is the navigation when "pjax does its thing"? Do you click a link? Do you press browser back button?

@tremby
Copy link
Author

tremby commented Mar 13, 2015

Yes, sorry, that wasn't clear. When clicking through to a different page via pjax the code at 0019136#diff-256b2e7d3ffe31142c00fa086e15d3a6R551 runs. This (as far as I can tell) marks the inline scripts as being runnable again. Then when the user hits "back" in the browser those scripts run again, and the one mentioned above has the noConflict call in it, which wipes out my $ and jQuery references since the external jquery hasn't been loaded again.

@mislav
Copy link
Collaborator

mislav commented Mar 13, 2015

Do you expect external jQuery to be reloaded every time? Why would you want that?

Can't you move jQuery and noConflict call to <head> of the whole site so it only gets loaded once and not per every pjax page?

@tremby
Copy link
Author

tremby commented Mar 13, 2015

Do you expect external jQuery to be reloaded every time? Why would you want that?

No, I never said I wanted that. Nothing has changed with how external scripts are handled. It is pjax's handling of inline scripts which has changed, and which is causing issues for me.

The purpose of this ticket is to point out that a pair of external and inline scripts might be used in this sort of way, in case it had not been considered. Perhaps you would want to reconsider rerunning one kind but not the other. And perhaps not. It does seem odd to me that they would be handled differently.

Can't you move jQuery and noConflict call to <head> of the whole site so it only gets loaded once and not per every pjax page?

No. As explained above, these scripts are injected by a debugging tool. I can't choose where they go. And I also acknowledged that it is likely best fixed there in that tool.

@mislav
Copy link
Collaborator

mislav commented Mar 13, 2015

The purpose of this ticket is to point out that a pair of external and inline scripts might be used in this sort of way, in case it had not been considered. Perhaps you would want to reconsider rerunning one kind but not the other.

I see. Thanks for reporting this.

I'll switch to unmarking <script src> as run as well. But, for them to run synchronously and in order, we'll first have to solve #331 (comment)

Until then, pjax doesn't work well with page contents that has a mix of external <script src> and inline <script> tags.

@mislav
Copy link
Collaborator

mislav commented May 23, 2017

Closing in favor of the above referenced issue (referenced scripts executing async).

@mislav mislav closed this as completed May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants