0

I have a kinnda weird issue. On the homepage (https://seekthelordca.org/) everything (assets) load properly (picture 1). Then if I clink on an other link of the navbar ('periodicals') and then click on 'Home' to go back to the homepage the assets (css) doesn't load properly (picture 2). I have 2 template layout; 1 for the homepage and 1 for the rest.

I'm calling my stylesheets like this:

<%= stylesheet_link_tag    'bootstrap_3_2.css', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css', 'style.min.css','responsive.min.css','demo.css',  media: 'all'%>

But what's seems weird is when I view the source of the homepage and click on every css link everything loads.

enter image description here

result when going to an other link and click back on 'Home' enter image description here

Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101

1 Answers1

1

Thanks, this was a fun 2 minute puzzle.

Please see the network logs below. This is on first load: enter image description here

And then clicking on another link and back again, this is the log: enter image description here

So, what is the difference? Well the first thing to note is that is the css is being loaded, and the same 4 JS files in the same order:

  • JQuery v1.11.0-pre
  • Bootstrap
  • Masonry
  • demo

However on the load that is from another link on the site, you have a second JQuery being loaded which is a different version (2.1.3). You also have another JS being loaded that is using this JQuery & loading Sizzle (it's called bookstore.js. One of these is highly likely to be messing up your layout. I would suspect that it was the mixed versions of JQuery.

As suggested within the comments, adding this line should prevent the assets being included from the other pages in this one:

add to config/environments/production.rb: config.action_view.cache_template_loading = false

ABrowne
  • 1,574
  • 1
  • 11
  • 21
  • Thanks @ABrowne for checking up the logs. So I changed the jquery to be the same for both layout but `jquery.min.js` doesn't load when visiting back the homepage. – Papouche Guinslyzinho Sep 06 '15 at 22:24
  • I see you have changed them, this is good. However you are still loading jQuery twice on the page via the route. May I ask what is the purpose of the bookstore.js? It appears to get included as soon as you navigate to another page and sticks to the header when on return to homepage. If you look at the source for the homepage there is no mention, however if you inspect the page you can clearly see it included within the header. Please consult this to ensure you are including that javascript on only the pages that are needed: http://railsapps.github.io/rails-javascript-include-external.html – ABrowne Sep 07 '15 at 00:28
  • Thanks ABrown!e it works now. Following this post http://stackoverflow.com/a/13975092/2581266 you could add to your answer to place `config.action_view.cache_template_loading = false` in `config/environments/production.rb` so that the assets will be cleared between different layouts – Papouche Guinslyzinho Sep 08 '15 at 19:30