Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Cache-Control: no-cache on responses #586

Merged
merged 3 commits into from
Jul 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sidecar/src/figwheel_sidecar/components/figwheel_server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[ring.util.response :refer [resource-response] :as response]
[ring.util.mime-type :as mime]
[ring.middleware.cors :as cors]
[ring.middleware.not-modified :as not-modified]
[org.httpkit.server :refer [run-server with-channel on-close on-receive send! open?]]

[com.stuartsierra.component :as component]))
Expand Down Expand Up @@ -200,6 +201,22 @@
#(possible-fn %)
#(handler %)))

(defn wrap-no-cache
"Add 'Cache-Control: no-cache' to responses.
This allows the client to cache the response, but
requires it to check with the server every time to make
sure that the response is still valid, before using
the locally cached file.

This avoids stale files being served because of overzealous
browser caching, while still speeding up load times by caching
files."
[handler]
(fn [req]
(some-> (handler req)
(update :headers assoc
"Cache-Control" "no-cache"))))

(defn server
"This is the server. It is complected and its OK. Its trying to be a basic devel server and
also provides the figwheel websocket connection."
Expand All @@ -217,6 +234,8 @@
(handle-index http-server-root)
(handle-figwheel-websocket server-state)

(wrap-no-cache)
(not-modified/wrap-not-modified)
;; adding cors to support @font-face which has a strange cors error
;; super promiscuous please don't uses figwheel as a production server :)
(cors/wrap-cors
Expand Down