diff options
author | Jacob Mitchell <jmitchell@member.fsf.org> | 2016-09-08 11:09:45 -0700 |
---|---|---|
committer | Jacob Mitchell <jmitchell@member.fsf.org> | 2016-09-08 11:09:45 -0700 |
commit | 40f5ea3c4242f8f92d511596778f980671972d7f (patch) | |
tree | a271152c69adc3c891deda1cfcc5a533ed00279a /src/cjr_print.sml | |
parent | 51ac19f565fa935eec6d9dd1f7119c6227383a3c (diff) |
Use hash instead of timestamp in app.js filename
Makes Ur/Web project builds reproducible without sacrificing HTTP
caching. Uses a public domain SHA1 implementation by tom7. See #38.
Diffstat (limited to 'src/cjr_print.sml')
-rw-r--r-- | src/cjr_print.sml | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 2e969c46..688b3e4d 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -55,6 +55,8 @@ structure CM = BinaryMapFn(struct val debug = ref false +val app_js = ref "" + val dummyTyp = (TDatatype (Enum, 0, ref []), ErrorMsg.dummySpan) val ident = String.translate (fn #"'" => "PRIME" @@ -2509,9 +2511,15 @@ fun p_decl env (dAll as (d, loc) : decl) = | DDatabase _ => box [] | DPreparedStatements _ => box [] - | DJavaScript s => box [string "static char jslib[] = \"", - string (Prim.toCString s), - string "\";"] + | DJavaScript s => + let + val () = app_js := OS.Path.joinDirFile {dir = Settings.getUrlPrefix (), + file = "app." ^ SHA1.bintohex (SHA1.hash s) ^ ".js"} + in + box [string "static char jslib[] = \"", + string (Prim.toCString s), + string "\";"] + end | DCookie s => box [string "/*", space, string "cookie", @@ -2948,15 +2956,11 @@ fun p_file env (ds, ps) = newline] end - val timestamp = LargeInt.toString (Time.toMilliseconds (Time.now ())) - val app_js = OS.Path.joinDirFile {dir = Settings.getUrlPrefix (), - file = "app." ^ timestamp ^ ".js"} - - val allScripts = + fun allScripts () = foldl (fn (x, scripts) => scripts ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n") - "" (Settings.getScripts () @ [app_js]) + "" (Settings.getScripts () @ [!app_js]) fun p_page (ek, s, n, ts, ran, side, dbmode, tellSig) = let @@ -3098,7 +3102,7 @@ fun p_file env (ds, ps) = val scripts = case side of ServerOnly => "" - | _ => allScripts + | _ => allScripts () in string scripts end, @@ -3509,7 +3513,7 @@ fun p_file env (ds, ps) = newline, newline, string "if (!strcmp(request, \"", - string app_js, + string (!app_js), string "\")) {", newline, box [string "uw_write_header(ctx, \"Content-Type: text/javascript\\r\\n\");", @@ -3633,7 +3637,7 @@ fun p_file env (ds, ps) = newline, if !hasJs then box [string "uw_set_script_header(ctx, \"", - string allScripts, + string (allScripts ()), string "\");", newline] else |