Fork me on GitHub
#untangled
<
2016-08-17
>
jasonjckn18:08:18

slightly off topic: my production javascript files are being cached, so that when I deploy a new app, the clients load stale SPAs until they invalidate their cache, any suggestions? I see wrap-not-modified middleware is in place https://github.com/untangled-web/untangled-server/blob/master/src/untangled/server/impl/components/handler.clj#L164 i thought that this handled cache invalidation, but I guess not

jasonjckn18:08:21

i know one of the main solutions is to append version number to JS filename / as a query param

therabidbanana18:08:12

Maybe hacky, but what we've been doing is linking to all assets with a git tag in the url (like: ["/assets/" :asset-tag "/application.js"]) which we under the hood just ignore and rewrite to /assets/application.js

therabidbanana18:08:32

So then we can make the caching headers far-future

therabidbanana18:08:39

Because every deploy will change it

jasonjckn18:08:06

nice like it

therabidbanana18:08:12

Technically clojure doesn't know that the asset-tag is a git sha - we set it as an environment variable in our deploy setup, but not sure if that's really a detail that matters other than it made it easier to script than requiring a git clj library

jasonjckn18:08:41

right, yah, i would be very hesitant to add a dependency on git

jasonjckn18:08:08

you could even do md5sum of the jar file and pass that as env var

therabidbanana18:08:44

Yeah, whatever wouldn't change - our deploy is currently git dependent, so that seemed like a reasonable approach.

therabidbanana18:08:32

Making it environment variable based did make it a lot easier to mess around with to test it was working as expected (and let us set a development only tag "0" that doesn't get caching headers).

jasonjckn18:08:49

what's weird to me is that i thought wrap-not-modified middleware looks at the timestamp of the file on disk, and compares that timestamp of file on clients disk

jasonjckn18:08:01

and that this would invalidate the cache if I modified my javascript file

jasonjckn18:08:09

maybe i don't understand the middleware well enough

jasonjckn18:08:11

i find it strange that this hack is required at all, that a ring server can't work with the client to invalidate files that have changed on the server

therabidbanana18:08:14

Relying just on not-modified requires a round trip to the server every time, which is why we also added Cache Control headers for our tagged requests

jasonjckn18:08:23

ok I think I get it now

therabidbanana18:08:49

Looks like wrap-not-modified still wants you to do the heavy lifting anyway

therabidbanana18:08:13

"Middleware that returns a 304 Not Modified from the wrapped handler if the handler response has an ETag or Last-Modified header, and the request has a If-None-Match or If-Modified-Since header that matches the response" ^ so you have to put your own ETag and Last-Modified values into headers for it to work

therabidbanana18:08:59

Though you'd think the middleware for serving static assets would do that

jasonjckn18:08:59

that's assuming the client even makes a request for a file it has cached

jasonjckn18:08:11

which I guess it will only do once TTL has been reached

jasonjckn18:08:19

the max-age value

therabidbanana18:08:53

Yeah, we set it up the way we did so we can make max-age a year so it never has to check in

therabidbanana18:08:06

(Unless you reload and the html links to a new js file)

tony.kay18:08:59

For anyone that has had problems with rendering and post-mutation (on data loads): I think I discovered a bug where post-mutations are not causing re-renders. I'm going to fix it (for now) by forcing a root re-render in the app when there are post mutations. This will be in 0.5.5-SNAPSHOT shortly.

tony.kay18:08:22

That fix has been pushed to clojars on the snapshot

therabidbanana19:08:01

Is snapshot going to release at some point? I know there was another fix on there for https://github.com/untangled-web/untangled-client/issues/21

tony.kay19:08:46

advanced optimizations is still not quite right with Om itself

tony.kay19:08:03

The fixes going on there will affect that, I believe

tony.kay19:08:12

(and will affect our implementation)

tony.kay19:08:29

basically anything declared "static" is getting killed by Closure

tony.kay19:08:58

alpha42 should fix that, which will let us clean up some code and have that work (hopefully)

tony.kay19:08:08

for now, use whitespace or simple

tony.kay19:08:29

My understanding is that this is actually a bug in Closure we're working around until it gets fixed.

therabidbanana19:08:55

Wow, the rabbit hole goes even deeper than I realized.

jasonjckn23:08:09

can I call load-field-action twice in the same mutation handler?

jasonjckn23:08:19

to load 2 different fields

tony.kay23:08:31

it just appends a load onto the sequential queue

tony.kay23:08:58

the thing you pass to :remote triggers an attempt to process it