2

According to the Ruby on Rails Guide: Caching, caching is disabled by default in the development and testing environments. If I make a small CSS change, run rails server and access my site at localhost:3000, I can see my change. However, if I access my rails server on my iPhone at 10.0.1.2:3000, the CSS doesn't update, even Chrome in Incognito Mode. When I try different iPhone that has an empty cache, the change is there.

I found a stack overflow post that described the same problem. Here were the suggested solutions:

  • Remove the public/assets directory. I don't have one.
  • Add config.serve_static_assets = false to environments/development.rb. It's already there.
  • Delete /tmp/cache/assets, add config.serve_static_assets = false to environments/development.rb and restart the server. I tried this and it didn't work.

Here's my relevant environments/development.rb config:

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Show full error reports and disable caching
config.consider_all_requests_local       = true
config.action_controller.perform_caching = false
Community
  • 1
  • 1
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149

4 Answers4

5

I'm pretty sure this is happening because Rails only does fingerprinting in production: http://guides.rubyonrails.org/asset_pipeline.html#in-production

This means that in development browsers that are more cache-aggressive can run into this issue.

Try adding this to your development.rb:

config.assets.digest = true

Or more preferable something conditional for when you're doing mobile development

# One of the few exceptions I'd make to a no ENV variables rule 
# for my rails environment config files
config.assets.digest = true if ENV["MOBILE_DEBUG"]
Alex Dixon
  • 613
  • 4
  • 11
0

How are use accessing your local machine via your iphone ?

have you configured any network settings or you push it to a different server and access from there, because the thing is if you are pusing it to a different server , that sever might be running in the production mode.

HTH

sameera207
  • 16,547
  • 19
  • 87
  • 152
  • I'm just hitting the IP address of my development machine instead of localhost (`http://10.0.1.2:3000` instead of `http://localhost:3000`). – LandonSchropp Jan 06 '13 at 07:26
  • In that case I'm suspecting the iphone browser cache has something to do with this, I'm sorry I'm not familiar with that area , probably you could post with same question with iphone category and get to know how its browser cache works.. :) – sameera207 Jan 06 '13 at 08:31
  • I added the iPhone category. – LandonSchropp Jan 08 '13 at 05:15
0

I don't have an iPhone to test, but it sounds like a normal browser caching issue. Try these instructions for clearing the browser cache. If that works, you'll need to do it each time you update your CSS (or J

James Mason
  • 4,246
  • 1
  • 21
  • 26
  • I thought one of the features of Rails was it was supposed to prevent browser caching by appending a hash string to the asset filenames in development mode. – LandonSchropp Jan 09 '13 at 08:13
  • It's supposed to, yeah. You can check the source of your webpage to make sure the asset URLs are being updated. It's possible your iPhone is caching the HTML page, so it's not even seeing the updated URL. Maybe some kind of mobile optimization. – James Mason Jan 09 '13 at 20:47
  • Clearing the browser cache works, but it's really annoying. I still feel like there should by some way of accomplishing this with Rails (such as appending a UUID to the asset file names on every request). – LandonSchropp Jan 13 '13 at 23:33
0

I had a similar problem. It happened because my config/environments/development.rb had contained config.asset_host = 'http://localhost:3000'

I've removed it and all works fine.