                                :page-conf {:page-name page-name}
                                :body-html bhtml)))))
 
+(defn fs [] (js/require "fs"))
+(defn path [] (js/require "path"))
+
 (defn mkdirs [f]
-  (let [fs (js/require "fs")
-        path (js/require "path")
-        items (as-> f _
-                (.' path dirname _)
-                (.' path normalize _)
+  (let [items (as-> f _
+                (.' (path) normalize _)
                 (string/split _ #"/"))]
     (doseq [d (reductions #(str %1 "/" %2) items)]
-      (when-not (.' fs existsSync d)
-        (.' fs mkdirSync d)))))
+      (when-not (.' (fs) existsSync d)
+        (.' (fs) mkdirSync d)))))
 
 (defn write-file [f content]
-  (mkdirs f)
-  (.' (js/require "fs") writeFileSync f content))
+  (mkdirs (.' (path) dirname f))
+  (.' (fs) writeFileSync f content))
 
 (defn read-file [f]
-  (.' (js/require "fs") readFileSync f))
+  (.' (fs) readFileSync f))
 
 (defn path-join [& paths]
-  (apply (.' (js/require "path") :join) paths))
+  (apply (.' (path) :join) paths))
 
 (defn read-files [files]
   (string/join "\n" (map read-file files)))

    (do (-> (or a.rswapfs
                (set! a.rswapfs (array)))
            (.push #(apply f % args)))
        nil)
    (do (set! a.rswapping true)
        (try (swap! a (fn [state]
                        (loop [s (apply f state args)]


;;; History

(defn init-history [page]
  (when-not history
    (let [html5 (and page
                     (.isSupported Html5History)
                     (#{"http:" "https:"} js/location.protocol))]
      (doto (set! history
