当我离开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 %}
答案 0 :(得分:1)
从压缩器中排除缩小的js和css文件,问题将得到解决。 (解决@Timmy O&#39; 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 %}