Compressor With Remote Script (Google Maps API)
I'm trying to integrate django-compressor into an existing django project for performance reasons.
I've added {% compress css %}
and {% compress js %}
tags around the blocks in my root template where all JS and CSS scripts are included by child templates (ie. all other pages on the site extend those blocks in the root template to put their page-specific files). This works perfectly most of the time, but one page has an embedded Google Map with a JS header:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=weather&key={% include "google_maps_api_key" %}&sensor=false">
This triggers an exception when rendering the page:
Caught UncompressableFileError while rendering: 'http://maps.googleapis.com/maps/api/js?libraries=weather&key=MYAPIKEY&sensor=false' isn't accessible via COMPRESS_URL ('/media/') and can't be compressed
Is there any way to tell django-compressor to skip this script? Is there some way to have it access and compress the remote script?
No, AFAIK this is not possible (without modifying django-compressor quite heavily). The best solution, based on your description, would be to have separate blocks for local, compressable scripts and remote scripts, and have your child templates use those appropriately.
Is it technically possible? Yes... You could download the map to your assets folder and then compress from there.
However, this is against Google's Terms of Use and may create some weird edge cases. Better bet is to move the tag for maps outside of {% compress %} call. Since google maps is already precompressed, and hosted on Google's fast CDN, your webpage will load faster anyway than if you tried to server yourself.
链接地址: http://www.djcxy.com/p/68514.html上一篇: Django压缩机标签在生产机器上被忽略