0

I have just written my first very basic Jquery Mobile site which has only two pages.

The second page (which could be the first) uses galleria slideshow which has its own js files.

The very strange thing that happened is that if I load page 2 first it runs perfectly fine. However if I run page 1 and then click the link to page 2, it hangs on page 1 and there is a js console error saying that galleria is undefined. I got past the error by including the galleria js files in page 1 and then everything worked fine.

So question is why should I need to do that? Surely these two pages are not connected in any way except the link. Any thoughts / ideas / explanations of this odd behaviour?

Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
RobC
  • 45
  • 8

1 Answers1

1

This isn't a strange behavior, it's exactly how jQuery Mobile works. In fact, jQM after loaded the first page, load the others using AJAX and simply injecting their body into the first page. If you want to verify this fact, use a DOM inspector. Said that, the <head> section of the others page is never loaded. To solve the problem you've to include the galleria library in each file you use or use something like PHP include (much better).

Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
  • Thanks, that explains it then. Good job I stumbled on the correct solution by trial error. But seems to put a heavy load of including all js in first page loaded even though it doesn't need it all. I guess someones going to tell me there's a way to only load the js files when you get to actually needing them. – RobC Feb 05 '13 at 15:28
  • I've just read some of the docs intro which I should have done before. I've now used ` data-ajax="false" ` to stop ajax load of page 2 which means I can reduce size of page 1 load which is what I wanted. – RobC Feb 05 '13 at 15:59
  • Yes, you should also add that attribute ;) – Aurelio De Rosa Feb 05 '13 at 16:21