johann
johann

Reputation: 1135

JavaScript code not loaded (only the first time)

When accessing the below url for the first time, most of javascript code is not loaded :

http://goo.gl/PxsVhZ

(images below the " WHY CHOOSE US ?" are not animated)

But if you refresh the page, javascript will be loaded and acts normally.

Project was created with RoR and deploy with capistrano (with asset compilation). Apache is used as proxy and send data to the web server (unicorn).

The site is still under development (english translation too...), thanks for your understanding.

EDIT : If animation appears during your first access, click on the "home" → "home" and then "home" → "why choose us".. javascript should be broken.

If someone has any idea, I would be glad to hear it ! Thank you

Upvotes: 1

Views: 3688

Answers (1)

Neeraj
Neeraj

Reputation: 180

Dont put your Javascript in footer. It should be in a file like app/assets/javascripts/myfile.js Then include this file in application.js with //= require myfile . Reason - when we navigate from one page to another, common templates like header and footer do not load again only the body changes (you can observe that visually). So, javascript in footer stays there and is visible in HTML source code but does not gets executed with second page load.

P.S. There are a few solutions http://blog.steveklabnik.com/posts/2013-06-25-removing-turbolinks-from-rails-4 or github.com/kossnocorp/jquery.turbolinks , To understand the problem and solutions Rails Jquery doesn't work on other pages

Upvotes: 3

Related Questions