问题标签 [django-compressor]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
5034 浏览

django - 强制 django_compressor 重新编译 css/less 文件

我们让用户将他们自己的自定义 css/less 上传到我们的 django 应用程序。

我们所有的 css/less 文件都由django_compressor “on-the-fly”压缩。

最初部署应用程序时,所有 css 文件都将移动到该collect-static目录。

当用户上传自定义 css 样式时,他们会替换collect-static目录中较少的文件之一。

问题在于这些更改仅在重新加载 apache 时才会出现,因此 django-compressor 会生成一个新的 css 文件。

有没有办法强制 django-compressor 重新生成它的编译和缓存文件?sudo services apache2 reload在 django 应用程序级别触发 a 时我会感到不舒服。

0 投票
1 回答
385 浏览

javascript - 压缩时 JavaScript 字符串连接中断

我最近决定开始在一个项目中使用 Django Compressor 来自动连接和缩小 js 和 css,并在它们更改时刷新缓存。

我遇到的问题是有些脚本在未压缩时可以工作,但在通过压缩器运行后它们会中断。我已经能够将可能性缩小到字符串连接。特别是 HTML 字符串连接。

例如:

压缩时断裂。我收到语法错误:

语法错误:缺少;声明之前

但这有效:

有人可以解释一下:

  1. 为什么会断?
  2. 我应该如何编写它以便在压缩时工作?

谢谢

编辑:这是引发错误的压缩代码部分:

它被扔在 RegExp(term, g) 中的“g”上

我发现这有效:

所以这解决了我让它工作的部分问题。但“为什么”的问题仍然存在。

玩的东西:

  • jQuery
  • 胡子
  • Django 压缩器 (JSmin)
0 投票
1 回答
463 浏览

git - Django 压缩器、git 和生产

我使用 amazon s3 存储静态文件,使用 django-compressor 压缩 js 和 css 文件COMPRESS_OFFLINE = True

要部署到我的生产服务器,我首先运行python manage.py compress,它将压缩文件上传到 Amazon s3,然后执行 git push 到我的存储库。在生产服务器上,我从这个 repo 中提取,我总是遇到生成的 css 和 js 文件之间的同步问题。

我搜索了可能性并注意到压缩器实际上查看了压缩文件的修改时间。当我检查我的应用程序的静态文件夹(不是 S3 文件)中的静态文件之间的修改日期时,我注意到它们是不同的,我相信原因是 git 更改了已更改文件的修改日期。

我怎样才能解决这个问题?

谢谢

0 投票
1 回答
267 浏览

django - 无法访问静态资源

我正在使用 Mezzanine、django-compressor 和 amazon-s3。我使用 django-compressor 来压缩 css 文件。我已经将网站部署到 Heroku 并成功存储了静态资源。但是,一段时间后,所有的CSS都丢失了。以下是来自 amazon-s3 的通知:

这是设置中的配置:

请帮我解决这个问题。我找不到根本原因。太感谢了。

0 投票
2 回答
738 浏览

python - 在生产中提供 django 压缩文件

在生产中部署 Django 解决方案时,我遇到了压缩和编译静态文件的问题。我让 Django 在 Nginx 反向代理下运行,该代理还负责提供静态文件。

找不到某些文件(特别是 js 和 css 文件),我注意到这是因为 settings.py 中的以下设置启用了压缩

那么,冻结预编译和压缩以便在生产中部署它们的最正确方法是什么?谢谢

0 投票
3 回答
2198 浏览

django - django-compressor + less 压缩文件但链接到原始文件

我有一个带有 django-compressor 1.2 的 django 1.4.2 应用程序,用于压缩较少的文件。

我在app/static/css/home.less中有我的 less 文件。它在static/CACHE/css/5208013a00a2.css 下输出一个 less 文件

在本地运行时(Debug=True,文件由 django 提供)我得到了正确的响应。我的 html(模板)文件中的以下输出:

在部署中运行时(Apache 提供文件)我的响应很糟糕。我的 html 文件中的以下输出:

这些文件是在static/CACHE/css/5208013a00a2.css下的部署中创建的,所以我假设没有权限问题。我在日志中没有任何问题。

settings.py 中的一些设置:

部署是通过结构进行的,它在虚拟环境下创建应用程序。

0 投票
1 回答
828 浏览

django - django 压缩器创建大量缓存文件

服务器位于负载均衡器后面,无论出于何种原因,压缩器在其中创建了数以万计的缓存文件/static/CACHE/js//static/CACHE/css/

我的 settings.py 中的唯一设置是:COMPRESS_ENABLED = True

我是否缺少清理缓存文件的设置?

0 投票
1 回答
930 浏览

django - django-compressor creates javascript with syntax errors

A bit of background... I'm setting up my new site's base template and I'm including some popular javascript libraries, such as AngularJS, Bootstrap's javascript files, and Underscore.js. Of course I wrap these files in {% compress js %}. Example code below:

I know django-compressor only runs the minification filters, so it's probably the minifiers not generating the correct Javascript output.

Here is the JS error I get with JSMin:

And the error from the file generated by SlimIt:

I'm not entirely sure what's going on here, it seems hard to believe the minifiers would generate incorrect files on these common js libraries.

Has anyone run into problems with django-compressor's Javascript filters messing up common libraries?

0 投票
2 回答
441 浏览

javascript - 带有远程脚本的 Django-Compressor (Google Maps API)

出于性能原因,我正在尝试将 django-compressor 集成到现有的 django 项目中。

我在根模板中的块周围添加了{% compress css %}标签{% compress js %},其中所有 JS 和 CSS 脚本都包含在子模板中(即站点上的所有其他页面都在根模板中扩展这些块以放置其特定于页面的文件)。这在大多数情况下都可以正常工作,但是一个页面有一个带有 JS 标头的嵌入式 Google 地图:

这会在渲染页面时触发异常:

有没有办法告诉 django-compressor 跳过这个脚本?有没有办法让它访问和压缩远程脚本?

0 投票
1 回答
1740 浏览

django - Separation of Static Files & Assets with Django Compressor & Usage of collectstatic

I'm having a really hard time getting my head around the use of django-compressor.

Here's what I'm attempting to accomplish:

Separation of Static Files & Assets (LESS, Coffeescript)

I would like to separate my LESS CSS and Coffeescript files into an assets directory

e.g.

Leaving static assets such as images in my static directory

e.g.

To do this, I've added the assets path to my STATICFILES_DIRS variable to allow django-compressor to find the files (which works as expected). Is this the correct approach? I have been trying to find an independent load path dedicated to django-compressor but didn't have any luck as I don't intend for these assets to be served as statics.

Collection of Files for Production Deployment

For deploying to production, I would then like the compiled CSS & JS files along with other media in my app/static directory (e.g. images and so on) to be collected to an app/static-prod directory. But this doesn't work out so well because the assets are also collected when using the collectstatic command.

e.g.

Using the ./manage.py compress command only takes tare of my compiled files, not photo.jpg or hello.txt in this example.

The only possible way I've found to do this is using the --ignore flag with collectstatic

e.g.

I've also messed around with the COMPRESS_ROOT and COMPRESS_URL configuration variables but these only cause further trouble. Changing COMPRESS_ROOT resolves the collectstatic issue but now when using the compress command, the generated files end up in a different location to the static files.

These solutions hardly seem elegant. Is there a better way to do this? I feel like I'm missing something.

Thanks in advance for any help :)