4

Working on a product page using Expresso Store and I'm encountering an intermittent javascript error:

Uncaught TypeError: undefined is not a function - store.js:142

It looks like a dependency problem (store.js depends on jQuery). The store.js is being added to the page asynchronously in the footer of the {exp:store:product} tag whereas jQuery is added to the page at the bottom of the page, just before the </body>. Depending on network performance and what is cached in the browser, occasionally the store.js loads before jQuery has loaded.

I dont want to move jQuery to the page header, so is there a way to specify where Expresso injects its JS (eg: a special JS template tag) or is there a way to force the store.js script tag to be synchronous and hence enforce the script loading order?

5

UPDATE: Store 2 includes the fix mentioned below.


It will be an option in the next version. In the meantime, you can fix it by opening mod.store.php, going down to about line 235, and changing this:

(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(script);

to this:

document.getElementsByTagName("body")[0].appendChild(script);

That should make sure the store.js script is added to the bottom of the page, after jQuery and other scripts.

  • Adrian, how would this answer differ for Store 2.x? – Alex Kendrick Nov 14 '13 at 21:21
  • In Store 2 the change above is implemented by default, so you should have no problem loading jQuery and other scripts in your page footer. – Adrian Macneil Nov 14 '13 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.