Module: check_mk
Branch: master
Commit: b67e8d53b6c9c1e0b93337b7e09fe46576233d16
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b67e8d53b6c9c1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jun 1 15:46:15 2015 +0200
#2260 Improved load time of Check_MK GUI
We did several things to further improve the load time of the Check_MK GUI.
For example we are now shipping minified (compressed) version of the Stylesheets
and Javascript source code files. If those files are available on a system, they
will be used.
If you encounter any problems related to the <tt>*_min*.js</tt> files, please
let us know. If you remove those compressed files, the uncompressed files will
be used.
---
.gitignore | 1 +
.werks/2260 | 16 ++++++++++++++++
ChangeLog | 3 +++
Makefile | 31 ++++++++++++++++++-------------
web/.f12 | 4 ++++
web/htdocs/htmllib.py | 15 +++++++++++++--
6 files changed, 55 insertions(+), 15 deletions(-)
diff --git a/.gitignore b/.gitignore
index 530c05a..0f5e6e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ check_mk-*.tar.gz
mk-livestatus-*.tar.gz
mkeventd-*.tar.gz
check-mk-*.exe
+*_min.js
var/
.bugs/.my_ids
.bugs/.last
diff --git a/.werks/2260 b/.werks/2260
new file mode 100644
index 0000000..7156a8d
--- /dev/null
+++ b/.werks/2260
@@ -0,0 +1,16 @@
+Title: Improved load time of Check_MK GUI
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.7i2
+Date: 1433166250
+Class: feature
+
+We did several things to further improve the load time of the Check_MK GUI.
+For example we are now shipping minified (compressed) version of the Stylesheets
+and Javascript source code files. If those files are available on a system, they
+will be used.
+
+If you encounter any problems related to the <tt>*_min*.js</tt> files,
please
+let us know. If you remove those compressed files, the uncompressed files will
+be used.
diff --git a/ChangeLog b/ChangeLog
index 00f500d..3f1d7f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
1.2.7i2:
+ Multisite:
+ * 2260 Improved load time of Check_MK GUI...
+
1.2.7i1:
Core & Setup:
diff --git a/Makefile b/Makefile
index 6a92aa5..fbaf00a 100644
--- a/Makefile
+++ b/Makefile
@@ -64,6 +64,7 @@ help:
@echo "make version --> switch to new version"
@echo "make headers --> create/update fileheades"
@echo "make healspaces --> remove trailing spaces in code"
+ @echo "setup --> prepare system for development"
check-permissions:
@echo -n "Checking permissions... with find -not -perm -444..." && [
-z "$$(find -not -perm -444)" ] && echo OK
@@ -84,6 +85,7 @@ dist: mk-livestatus mk-eventd
tar czf $(DISTNAME)/notifications.tar.gz $(TAROPTS) -C notifications $$(cd notifications
; ls)
tar czf $(DISTNAME)/inventory.tar.gz $(TAROPTS) -C inventory $$(cd inventory ; ls)
tar czf $(DISTNAME)/checkman.tar.gz $(TAROPTS) -C checkman $$(cd checkman ; ls)
+ $(MAKE) minify-js optimize-images
tar czf $(DISTNAME)/web.tar.gz $(TAROPTS) -C web htdocs plugins
tar czf $(DISTNAME)/livestatus.tar.gz $(TAROPTS) -C livestatus $$(cd livestatus ; echo
$(LIVESTATUS_SOURCES) )
tar czf $(DISTNAME)/mkeventd.tar.gz $(TAROPTS) -C mkeventd $$(cd mkeventd ; echo * )
@@ -198,25 +200,28 @@ optimize-images:
mv $$F.opt $$F; \
done
+minify-js:
+ @for F in $$(cd web/htdocs/js ; ls *.js); do \
+ if [ $${F/_min/} == $$F ] ; then \
+ NAME=$${F%.*} ; \
+ SRC=web/htdocs/js/$$F ; \
+ DST=web/htdocs/js/$${NAME}_min.js ; \
+ if [ ! -f $$DST ] || [ $$(stat -c%Y $$SRC) -gt $$(stat -c%Y $$DST) ]; then \
+ echo "Minifying $$F..." ; \
+ cat $$SRC | slimit > $$DST ; \
+ fi ; \
+ fi ; \
+ done
+
clean:
rm -rf dist.tmp rpm.topdir *.rpm *.deb *.exe \
mkeventd-*.tar.gz mk-livestatus-*.tar.gz \
$(NAME)-*.tar.gz *~ counters autochecks \
- precompiled cache
+ precompiled cache web/htdocs/js/*_min.js
find -name "*~" | xargs rm -f
mrproper:
git clean -xfd -e .bugs 2>/dev/null || git clean -xfd
-
-## Do we really need this crap here any longer?
-## setup:
-## $(MAKE) dist
-## rm -rf $(DISTNAME)
-## tar xzf $(DISTNAME).tar.gz
-## cd $(DISTNAME) && ./setup.sh --yes
-## rm -rf $(DISTNAME)
-## check_mk -R
-## /etc/init.d/apache2 reload
-
-
+setup:
+ sudo apt-get install figlet pngcrush slimit
diff --git a/web/.f12 b/web/.f12
index bfab15b..d29bc30 100644
--- a/web/.f12
+++ b/web/.f12
@@ -1,6 +1,7 @@
#!/bin/bash
SITE=${SITE:-$(cat ../.site 2>/dev/null || true)}
SITE=${SITE:-$(omd sites --bare | head -n 1)}
+make -C .. minify-js
sudo rsync \
--exclude=defaults.py \
--exclude "*mkevent*" \
@@ -13,5 +14,8 @@ if [ "$SITE" != - ] ; then
sudo omd restart $SITE apache
fi
+# Nicht mit minifizierten Dateien entwickeln
+#sudo rm -f /omd/sites/$SITE/share/check_mk/web/htdocs/js/*_min.js
+
# Gecache PNP-Schablonen entfernen
sudo rm -f /omd/sites/$SITE/var/check_mk/pnp_template_cache/*
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 8d34682..4d75dd1 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -804,6 +804,8 @@ class html:
if defaults.omd_root:
if os.path.exists(defaults.omd_root +
"/share/check_mk/web/htdocs/" + css + ".css"):
fname = '%s-%s.css' % (css, defaults.check_mk_version)
+ else:
+ continue
else:
fname = '%s.css' % css
@@ -815,13 +817,22 @@ class html:
self.add_custom_style_sheet()
- # Load specified Javascript files
+ # Load specified javascript files. We have some special handling here:
+ # a) files which can not be found shal not be loaded
+ # b) in OMD environments, add the Check_MK version to the version (prevents
update problems)
+ # c) load the minified javascript when not in debug mode
for js in [ "checkmk", "graphs" ] + javascripts:
if defaults.omd_root:
- if os.path.exists(defaults.omd_root +
"/share/check_mk/web/htdocs/js/" + js + ".js"):
+ base_dir = defaults.omd_root +
"/share/check_mk/web/htdocs/js"
+ if not self.enable_debug and os.path.exists(base_dir + "/"
+ js + "_min.js"):
+ fname = '%s_min-%s' % (js, defaults.check_mk_version)
+ elif os.path.exists(base_dir + "/" + js +
".js"):
fname = '%s-%s' % (js, defaults.check_mk_version)
+ else:
+ continue
else:
fname = '%s' % js
+
self.javascript_file(fname)
if self.browser_reload != 0: