Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Unified Diff: grit/format/data_pack.py

Issue 375523002: Experimenting with rjsmin in grit. Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Cleaned up and moved rjsmin. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | grit/format/rjsmin.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/data_pack.py
diff --git a/grit/format/data_pack.py b/grit/format/data_pack.py
index 02616c39d40443d1c583f3acb351c7708f13ec54..9f85bb025eac66b478f711d748eb33047aa2a721 100755
--- a/grit/format/data_pack.py
+++ b/grit/format/data_pack.py
@@ -7,6 +7,11 @@
files.
"""
+import os
+import sys
+
+import rjsmin
+
import collections
import exceptions
import os
@@ -43,6 +48,17 @@ def Format(root, lang='en', output_dir='.'):
if isinstance(node, (include.IncludeNode, message.MessageNode,
structure.StructureNode)):
id, value = node.GetDataPackPair(lang, UTF8)
+ txt_id = node.GetTextualIds()[0]
+
+ # Use rjsmin to compress JavaScript resources. Closure would
+ # be even better but is tricky to integrate into the build
+ # system since it is Java.
+ if "_JS" in txt_id[-3:]:
+ size = len(value)
+ packed_value = rjsmin.jsmin(value)
+ packed_size = len(packed_value)
+ if packed_size < size:
+ value = packed_value
if value is not None:
data[id] = value
return WriteDataPackToString(data, UTF8)
« no previous file with comments | « no previous file | grit/format/rjsmin.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698