Skip to content

Commit 93ae26f

Browse files
authored
docs: more robust solution to Safari dev cache bug (#476)
1 parent 4433471 commit 93ae26f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

docs/src/guide/troubleshooting.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,23 @@ This is probably the case if you are seeing errors such as `#<Errno::EMFILE: Too
158158

159159
Follow [this article][ulimit] for information on how to increase the limit of file descriptors in your OS.
160160

161-
### Safari does not reflect CSS changes in development
161+
### Safari does not reflect CSS and JS changes in development
162162

163-
Safari [ignores](https://apple.stackexchange.com/questions/439451/safari-is-caching-hard-i-have-to-empty-for-each-change-in-my-css) the `Cache-Control: no-cache` header for CSS stylesheets, which is inconvenient in development as HMR for CSS does not work as expected, requiring the cache to be cleared manually in order to see changes.
163+
Safari [ignores](https://bugs.webkit.org/show_bug.cgi?id=193533) the `Cache-Control: no-cache` header for preloaded CSS and JS files, which is inconvenient in development as HMR does not work as expected, requiring the cache to be cleared manually in order to see changes.
164164

165-
A workaround is to import the CSS from a [`vite_javascript_tag` entrypoint][smart output] instead of using `vite_stylesheet_tag`. When the CSS is requested in this way it becomes a JS request in development, avoiding the bug in Safari.
165+
By default, Rails javascript and stylesheet tag helpers cause a `Link: ... rel=preload` header to be emitted, which triggers the Safari bug. As a workaround, you can disable the preload behavior in development as follows:
166+
167+
```ruby
168+
# config/environments/development.rb
169+
170+
Rails.application.configure do
171+
# Disable `Link: ... rel=preload` header to workaround Safari caching bug
172+
# https://bugs.webkit.org/show_bug.cgi?id=193533
173+
config.action_view.preload_links_header = false
174+
end
175+
```
176+
177+
With preloading disabled, Safari will properly refresh changed files and HMR will work.
166178

167179
## Fixed Issues
168180

0 commit comments

Comments
 (0)