diff --git a/src/clj_jtwig/web/web_functions.clj b/src/clj_jtwig/web/web_functions.clj
index 8e01b67..4033f83 100644
--- a/src/clj_jtwig/web/web_functions.clj
+++ b/src/clj_jtwig/web/web_functions.clj
@@ -32,6 +32,26 @@
(str url "?" modification-timestamp)
url))
+(defn- minified-url? [url]
+ (re-matches #"^(.+\.)min\.(css|js)$" url))
+
+(defn- make-minified-url [^String url]
+ (let [pos (.lastIndexOf url (int \.))]
+ (if (> pos -1)
+ (let [name (subs url 0 pos)
+ extension (subs url (inc pos))]
+ (str name ".min." extension))
+ url)))
+
+(defn- get-minified-resource-url [url]
+ (if (or (not (:check-for-minified-web-resources @options))
+ (minified-url? url))
+ url
+ (let [minified-url (make-minified-url url)]
+ (if (get-resource-path (str root-resource-path minified-url))
+ minified-url
+ url))))
+
; defined using the same type of map structure as in clj-jtwig.standard-functions
(defonce web-functions
@@ -41,11 +61,14 @@
"stylesheet"
{:fn (fn [url & [media]]
- (let [fmt (if media
- ""
- "")]
- (format fmt (get-url-string url) media)))}
+ (let [fmt (if media
+ ""
+ "")
+ resource-path (get-minified-resource-url url)]
+ (format fmt (get-url-string resource-path) media)))}
"javascript"
{:fn (fn [url]
- (format "" (get-url-string url)))}})
+ (let [fmt ""
+ resource-path (get-minified-resource-url url)]
+ (format fmt (get-url-string resource-path))))}})