COMPRESS_ENABLED = True 时 Django-compressor js 文件不工作
Django-compressor js files not working when COMPRESS_ENABLED = True
当我离开 COMPRESS_ENABLED = False
时,一切正常,但我正在加载的 js 文件未压缩。
但是,如果我设置 COMPRESS_ENABLED = True
,压缩文件似乎可以正确压缩和加载。问题是,我正在压缩的库没有正确加载。例如,我收到 jQuery.
的 $ is not defined
错误
我能看到的唯一线索是我在压缩文件的第一行收到 Uncaught SyntaxError: Unexpected identifier
错误。我需要做什么才能让浏览器读取这个压缩文件?
谢谢!
我的设置文件是:
COMPRESS_ENABLED = True
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
HTML 是:
{% load compress %}
{% compress js %}
<script type="text/javascript" src="/static/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/static/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/static/react/react.min.js"></script>
<script type="text/javascript" src="/static/jquery-cookie/jquery.cookie.js"></script>
<script type="text/javascript" src="/static/image-picker/image-picker.min.js"></script>
{% endcompress %}
从压缩器中排除缩小的 js 和 css 文件,问题将得到解决。 (由@Timmy O'Manhony 评论解决)
{% load compress %}
<script type="text/javascript" src="/static/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/static/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/static/react/react.min.js"></script>
<script type="text/javascript" src="/static/image-picker/image-picker.min.js"></script>
{% compress js %}
<script type="text/javascript" src="/static/jquery-cookie/jquery.cookie.js"></script>
{% endcompress %}
当我离开 COMPRESS_ENABLED = False
时,一切正常,但我正在加载的 js 文件未压缩。
但是,如果我设置 COMPRESS_ENABLED = True
,压缩文件似乎可以正确压缩和加载。问题是,我正在压缩的库没有正确加载。例如,我收到 jQuery.
$ is not defined
错误
我能看到的唯一线索是我在压缩文件的第一行收到 Uncaught SyntaxError: Unexpected identifier
错误。我需要做什么才能让浏览器读取这个压缩文件?
谢谢!
我的设置文件是:
COMPRESS_ENABLED = True
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
HTML 是:
{% load compress %}
{% compress js %}
<script type="text/javascript" src="/static/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/static/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/static/react/react.min.js"></script>
<script type="text/javascript" src="/static/jquery-cookie/jquery.cookie.js"></script>
<script type="text/javascript" src="/static/image-picker/image-picker.min.js"></script>
{% endcompress %}
从压缩器中排除缩小的 js 和 css 文件,问题将得到解决。 (由@Timmy O'Manhony 评论解决)
{% load compress %}
<script type="text/javascript" src="/static/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/static/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/static/react/react.min.js"></script>
<script type="text/javascript" src="/static/image-picker/image-picker.min.js"></script>
{% compress js %}
<script type="text/javascript" src="/static/jquery-cookie/jquery.cookie.js"></script>
{% endcompress %}