Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my CSS go screwy "sometimes"

A website of mine is behaving weirdly. The layout sometimes is fine, and sometimes it is screwy. An example page that I see the problem on is this one: link

Disclaimer: I have yet to start my investigation into cause in earnest. I am turning to Stackoverflow because I am lazy and I hope someone will say "That happened to me once, it is probably this...". So please, no one get stuck into this working out this issue if it is something you have never seen before, as it wouldn't be fair as I have not done it myself.

Ok, some background:

  • The problem usually (maybe always) occurs when first viewing the page
  • The problem does not show up always, only sometimes
  • When the page shows up munged, if you refresh it usually reloads looking as it should
  • The site is a rails app
  • The css is passed through the neat Smurf Gem, which automatically minifies the CSS and Javascript on the page.
  • The layout problems happen in firefox (both linux and winXP)
  • The CSS is served up in the production environment using the ":cache => true" option which concatenates all the css files into one file

Anyway, I am hoping that this has happened to someone before and it will be really simple to fix. If not, I'll go and investigate and return with the solution (or a request for more help).

Thanks in advance!

James.

[edit]I added the first two bullet points, inspired by the comments and first answer[/edit]

like image 282
James P McGrath Avatar asked Nov 15 '22 07:11

James P McGrath


1 Answers

We have had something similar when using HAML and SASS that resulted in the CSS being completely unavailable. It only happened on deploys. We determined it was a combination of the Rails stylesheet merging and the generation of the CSS from SASS. Sass was not done generating the CSS, which it did so on the first request to the application, when Rails attempted to merge it all together. The result, a corrupt useless CSS file. Then we stumbled upon this article which has a solution for preventing this issue.

Based on all this, my best guess is that the Smurf gem is attempting to generate your file on the first request, but Rails is serving it out before its done. The generation completes then each following request is fine. If this is the problem then the only solution i know of is to get the file generated before the first request. Of course, this does assume that it is related to deployments or application restarts in some way.

Peer

like image 90
Peer Allan Avatar answered Nov 24 '22 01:11

Peer Allan