Search code examples
javascriptjqueryhtmlcssbackbone.js

Page only loads CSS and JavaScript after refresh


The first time I load the page it's a mess and JavaScript functions don't work. The second time it looks ok and works.

Any brief idea what might be causing this behaviour? I'm using Backbone.js and jQUery Mobile if that makes a difference.

Sorry for no code, but I need to go to a meeting in a moment and the website is huge so I don't really know what part to show you.

If anybody knows why this is happening and doesn't need to see the code, please help.

UPDATE:

Here's what seems to be the answer: https://forum.jquery.com/topic/script-not-running-unless-i-refresh-page

Thank you for suggestions, I upvoted the ones that seem relevant.


Solution

  • It sounds like unmet dependencies: some of your functions probably run before the document is fully loaded and can't get their job done correctly (missing elements, etc..). The second time the function work beacuse the page is cached and so loaed in time before the function starts.

    I'd start looking at the JavaScript console and post the errors here if you can't figure it out alone, but without proper informations what we could do is just poor absumptions.