Permalink
Browse files

do not block on HTTP errors when fetching external JS/CSS

  • Loading branch information...
cvan committed Aug 30, 2012
1 parent 16d813d commit d1b668ad7c0423fe8cc639df36d433da5c168cac
Showing with 18 additions and 11 deletions.
  1. +6 −6 examples/minify/settings.py
  2. +12 −5 jingo_minify/management/commands/compress_assets.py
@@ -23,16 +23,16 @@
'common': ['css/test.css'],
'common_url': ['http://example.com/test.css'],
'common_protocol_less_url': ['//example.com/test.css'],
- 'common_bundle': ['css/test.css', 'http://example.com/test.css',
- '//example.com/test.css',
- 'https://example.com/test.css']
+ 'common_bundle': ['css/test.css', 'http://example/test.css',
+ '//example/test.css',
+ 'https://example/test.css']
},
'js': {
'common': ['js/test.js'],
'common_url': ['http://example.com/test.js'],
'common_protocol_less_url': ['//example.com/test.js'],
- 'common_bundle': ['js/test.js', 'http://example.com/test.js',
- '//example.com/test.js',
- 'https://example.com/test.js'],
+ 'common_bundle': ['js/test.js', 'http://example/test.js',
+ '//example/test.js',
+ 'https://example/test.js'],
},
}
@@ -76,10 +76,16 @@ def handle(self, **options):
for ftype, bundle in settings.MINIFY_BUNDLES.iteritems():
for name, files in bundle.iteritems():
- # Set the paths to the files
+ # Set the paths to the files.
concatted_file = path(ftype, '%s-all.%s' % (name, ftype,))
compressed_file = path(ftype, '%s-min.%s' % (name, ftype,))
- files_all = [self._preprocess_file(fn) for fn in files]
+
+ files_all = []
+ for fn in files:
+ processed = self._preprocess_file(fn)
+ # If the file can't be processed, we skip it.
+ if processed is not None:
+ files_all.append(processed)
# Concat all the files.
tmp_concatted = '%s.tmp' % concatted_file
@@ -90,7 +96,7 @@ def handle(self, **options):
self._call("cat %s > %s" % (' '.join(files_all), tmp_concatted),
shell=True)
- # Cache bust individual images in the CSS
+ # Cache bust individual images in the CSS.
if cachebust_imgs and ftype == "css":
bundle_hash = self._cachebust(tmp_concatted, name)
self.bundle_hashes["%s:%s" % (ftype, name)] = bundle_hash
@@ -152,11 +158,11 @@ def _preprocess_file(self, filename):
except urllib2.HTTPError, e:
print ' - HTTP Error %s for %s, %s' % (url, filename,
str(e.code))
- return ''
+ return None
except urllib2.URLError, e:
print ' - Invalid URL %s for %s, %s' % (url, filename,
str(e.reason))
- return ''
+ return None
with open(file_path, 'w+') as fp:
try:
@@ -166,6 +172,7 @@ def _preprocess_file(self, filename):
filename = os.path.join('external', filename)
else:
print ' - Not a valid remote file %s' % filename
+ return None
if filename.endswith('.less'):
fp = path(filename.lstrip('/'))

0 comments on commit d1b668a

Please sign in to comment.