1

django-compress を使用して、manage.py compress コマンドを使用して、Amazon S3 に保存されている js と css を事前圧縮しています。

ただし、問題は、css 内の相対 img URL が絶対 URL に置き換えられていないことです。

だから私はCSSのような画像のURLを持っています

background-image:url("../img/image1.png")

これは、compress コマンドを実行した後、イメージの絶対 S3 URL に適切に置き換えられません。のようなものになる代わりに

https://webappbucket.s3.amazon.com/img/image1.png 

それはそのまま

"../img/image1.png"

圧縮されたcssで。

settings.py の私の django-compress 設定は次のとおりです。

STATICFILES_DIRS = (
    'webapp/static',
)

INSTALLED_APPS += ('storages',)

STATICFILES_STORAGE = 'lib.storage.CachedS3BotoStorage'

AWS_ACCESS_KEY_ID = constants.AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY = constants.AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME = constants.S3_BUCKET_NAME
S3_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL

#compress
COMPRESS = True
COMPRESS_OFFLINE = True
COMPRESS_ROOT = "../"
COMPRESS_ENABLED = True
COMPRESS_STORAGE = STATICFILES_STORAGE

COMPRESS_JS_FILTERS = [
    'lib.compressor_filters.YUglifyJSFilter',
]

COMPRESS_CSS_FILTERS = [
    'lib.compressor_filters.YUglifyCSSFilter',
]

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)

COMPRESS_YUGLIFY_BINARY = 'node_modules/yuglify/bin/yuglify' # assumes yuglify is in your path
COMPRESS_YUGLIFY_CSS_ARGUMENTS = '--terminal'
COMPRESS_YUGLIFY_JS_ARGUMENTS = '--terminal'

COMPRESS_URL = STATIC_URL

STATIC_ROOT = "../"

AWS_QUERYSTRING_AUTH = False
4

1 に答える 1