当我离开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 %}