0

There is a link on a page. When I click on it I, indeed, get redirected to another page. But for the first time (when the referral in another page with the link) none of the js file load. None at all. Only when I reload it manually or type in the link in the address bar, then all the js files load normally. But for the first time - not.

It happens on both development and production environments. I suspect that caching might be a cause but some js files remain having "304 Not modified" even after reloading (some do not, though).

I use turbolinks if this matters.

What's the matter?

Incerteza
  • 32,326
  • 47
  • 154
  • 261
  • This can append if you are manually including js files and using turbo_links at the same time. you should post your js manifest file, your layout file and one of the view where you have this error – Benjamin Bouchet Jun 27 '14 at 03:36

1 Answers1

1

Assuming you're using the Asset Pipeline you can try incrementing the version of your assets by setting config.assets.version to something new (in config/application.rb). This should expire all of your existing assets and force new ones to be downloaded by your browser (and the browsers of all of your users too!).

pdobb
  • 17,688
  • 5
  • 59
  • 74
  • Do you mean, I can increment it once then run the server and it will always make the js load? I even don't have this key in my application.rb – Incerteza Jun 27 '14 at 09:56
  • I'm not guaranteeing always-loading JS assets here, just that it will force the assets to expire. The mechanism behind this being that the md5 fingerprint embeded in the asset names will be rehashed and, therefore, will look like new assets to the browser. If there's something else going on (i.e. if this isn't really a cached assets issue) then this won't fix the issue, I guess. What version of rails are you running? In 4.1 the `config.assets.version` is moved to an initializer file (config/initiailzers/assets.rb) and is defined as e.g. `Rails.application.config.assets.version = '1.0'`. – pdobb Jun 27 '14 at 12:52
  • please take a look at this http://stackoverflow.com/questions/24464958/an-element-in-document-ready-is-undefined-in-a-certain-situation – Incerteza Jun 28 '14 at 08:12
  • Ahh, OK. The caching thing threw me. It was just that you didn't understand the way turbolinks works yet, then? Hope you've got it now! – pdobb Jun 28 '14 at 12:04