A few weeks ago, I worked on a pull request for Forem/DEV.to. Everything went great, and it ended up getting merged! 🎉
The next day, I went to work on a different Ruby on Rails app, the framework that powers DEV.to, only to find my localhost:3000 was DEV.to-ified.
Since Forem uses Redis, an in-memory key-value data store that's commonly used for caching, I thought the view was still being cached. You might think (and so did I) that running
redis-cli flushall would do the trick, but nope.
I really wanted to avoid clearing my Chrome cache, so I switched the Rails server port to 4000 and opened
localhost:4000, and everything was fine.
It's worth noting that a hard refresh, or running Chrome in incognito mode, would briefly solve the issue, but eventually, the Forem views came back.
I finally reached out to Andrew Mason on Twitter who suggested the following:
- clearing local storage, session storage, and cookies in dev tools
- going into the Rails console and running
- and finally restarting my computer
It turns out DEV.to uses a custom serviceworker, versus using something like Google's Workbox, to handle some caching, you can see it in your browser dev tools.
If you run into this on your localhost, or the app won't load the page all the way in production, you can fix this by going to the above page in dev tools and click "unregister" on the service worker.
Your Rails app will be 100% less DEV.to-ified, and if it's in production, the page should load immediately.
I've opened an issue on the Forem GitHub repo where we can discuss possible solutions.
Describe the bug
After working on Forem locally and then switching to a new Rails app on the same port, the DEV.to header and footer still show.
- Start Forem up
- Close the server
- Open a Rails app on the same server
Not maintain cache
Desktop (please complete the following information):
- OS, version: Catalina, 10.15.6
- Browser, version: Chrome, 85
- This doesn't happen on Safari
- Probably isn't limited to Rails apps on the same port
Big thank you to Andrew for helping me with this blog post, and with figuring out how to fix this issue.