Reputation: 141
Im strugling with wierd error on my eshop. It dont always show, I even didnt know about it, because on my PC it dont shows, but I made debug function that send all javascript errors to my email. I get ReferenceError: po_zaladowaniu_strony is not defined po_zaladowaniu_strony is function that should be run as last after page load, it sets everything up etc. I head i have (as a first scripts):
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script type="text/javascript" src="/js/po_zaladowaniu.js?v=<?php echo date(U); ?>" ></script>
<script type="text/javascript" src="/js/strona.js?v=<?php echo date(U); ?>" ></script>
then before closing body tag i have:
<script type='text/javascript' src='https://code.jquery.com/ui/1.11.4/jquery-ui.min.js' defer></script>
<script type='text/javascript' src="https://code.jquery.com/jquery-migrate-1.2.1.min.js" ></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js" defer></script>
<script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js" defer></script>
<script src="/js/lightbox.js" defer></script>
<script type="text/javascript">
jQuery(document).ready( function(){
<!-- ODPALA Skrypty potrzebne po załadowaniu strony -->
po_zaladowaniu_strony("<?php echo $_SESSION["sesja_id"] ?>","<?php echo $_SESSION["typ"]; ?>");
});
</script>
po_zaladowaniu_strony function have its subfunctions in po_zaladowaniu.js and strona.js that are declared as first in html. So, why is that error occuring some times?
Upvotes: 0
Views: 658
Reputation: 141
The problem was with defer
. Thanks to freedomn-m who pointed out, in a comment that:
Depending on the browser,
defer
can load your script after your doc.ready - remove thedefer
to be safe. Decent modern browsers cache parsed scripts anyway, so those will likely already be in the browser cached, already parsed, reducing the need fordefer
. More info on SO with a link stackoverflow.com/a/8638597/2181514
Upvotes: 1