Skip to content

Instantly share code, notes, and snippets.

@gregawoods
Last active August 29, 2015 14:02
Show Gist options
  • Save gregawoods/071a8994cabc38dd786f to your computer and use it in GitHub Desktop.
Save gregawoods/071a8994cabc38dd786f to your computer and use it in GitHub Desktop.
Resolve issue where Safari 7 and iOS 7 Mobile Safari incorrectly render cached pages when a 304 response is returned from the server.
class ApplicationController < ActionController::Base
before_filter :delete_if_none_match_header
private
# Encountered bug where Safari 7 would fail to render pages when ETAG-based caching kicks in
# This should prevent Safari from attempting such caching
def delete_if_none_match_header
if request.format.html? && request.headers['If-None-Match'] != nil && is_safari?()
request.headers['If-None-Match'] = nil
end
end
def is_safari?
ua = request.env['HTTP_USER_AGENT']
return (ua.match('Intel Mac OS X') || ua.match('iPhone OS')) && ua.match('Safari')
end
end
@gregawoods
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment