defunkt / jquery-pjax

pushState + ajax = pjax
https://pjax.herokuapp.com
MIT License
16.73k stars 1.97k forks source link

Inline script need preload js file. #587

Closed page7 closed 9 years ago

page7 commented 9 years ago

inline script need js file be loaded, like plugin file. without event "pjax:end" or other.

<script src="preload.js"></script>

<img onload="preload()" data-src="xxx.jpg" src="blank.jpg" />
page7 commented 9 years ago

Sorry. Also there is some wrong with this update. Don't commit now. I will update again.

page7 commented 9 years ago

Why set <script> with "src" to obj.scripts ? jquery .html function let "ready" event after loaded script files ( same in ajax ). but in pjax, "ready" will run frist. I try to use $.holdReady() to delay the "ready" on pjax page, but no effect...

mislav commented 9 years ago

This is a known issue; see #331

We won't make the change you suggested because that would break other use cases. Namely, scripts on a specific page often expect that markup is already initialized on that page.

To solve your case, please ensure that preload() is a function defined globally in your javascript environment even before pjax navigation (such as in site's <head>).

page7 commented 9 years ago

But only use jquery html will do the "ready" method after script file loaded. I create a new reday deferred in pjax. so it do well now. I will push the update again to show you.