I’m trying to use code splitting in my CLJS codebase to separate app code from trackers (think Google Analytics), so that trackers code are not part of the base module and are lazy loaded on-demand only. Good idea, right ?
goog.require() etc.) to seamlessly package them an call them from CLJS. So far so good. Works perfectly, already in production for a long time.
Problems appear when I decided to code split them. Basically the split tracker module code is in the main app code split (
cljs_base.js), and the tracker module split (
google_analytics.js) is empty…
Below the details:
- Boot 2.7.1 with boot-cljs 2.1.4
- Clojure 1.9
- ClojureScript 1.9.946
- Java 8
CLJS wrapper code
(ns yoda.tracking.google-analytics (:require [cljs.loader :as loader] [trackers.google-analytics :as ga])) (defn start [ga-tracking-id entity] (ga/start ga-tracking-id entity)) (loader/set-loaded! :google-analytics)
(loader/load :google-analytics (fn  ((resolve 'yoda.tracking.google-analytics/start) ga-tracking-id entity)))
:verbose true option, the CLJS compiler seems to behave well:
Building module :google-analytics # lot of entries... adding entry [trackers.google-analytics] adding entry (yoda.tracking.google-analytics) module :google-analytics depends on :cljs-base
The browser console shows it’s working :
log:Module loaded: cljs_base log:Module loaded: google_analytics
- There’s no network request to load
google_analytics.jsis an empty file (contains only the source-map comment
cljs_base.jscontains everything, including the namespace
It seems to be related to cross module code motion, but I don’t understand why it produces this result. I think I’ve followed the official guide on Code Splitting to the letter.
Do you see where I’m wrong ?
Thanks in advance !
PS: I first posted in the official CLJS mailing list, but it seems that posts require approval first, so I posted here too in the meantime (had to rewrite it! no draft! arghh!). Sorry for the cross posting.