PERF: Correctly memoize baseUri value in javascript app (#9986)

PERF: Correctly memoize baseUri value in javascript app (#9986)

An empty string is a falsey value in javascript, so we were looking for the meta tag every time getURL was called, which took approximately 1.5ms every time.

diff --git a/app/assets/javascripts/discourse-common/addon/lib/get-url.js b/app/assets/javascripts/discourse-common/addon/lib/get-url.js
index eb36586..a74ea5f 100644
--- a/app/assets/javascripts/discourse-common/addon/lib/get-url.js
+++ b/app/assets/javascripts/discourse-common/addon/lib/get-url.js
@@ -4,7 +4,7 @@ let S3BaseUrl, S3CDN;
 export default function getURL(url) {
   if (!url) return url;
 
-  if (!baseUri) {
+  if (baseUri === undefined) {
     baseUri = $('meta[name="discourse-base-uri"]').attr("content") || "";
   }
 

GitHub sha: 731263b8

2 Likes

This commit appears in #9986 which was merged by davidtaylorhq.