我尝试压缩我的CSS和JS文件,因为我将Installtool中的compressionLevel设置为9,用于BE和FE。我在我的模板中添加了以下Typoscript到我的setup.txt:
config.compressCss = 1
config.compressJs = 1
config.concatenateCss = 1
config.concatenateJs = 1
plugin.tx_vhs.settings.asset {
fonts1 {
type = css
name = font1
path = https://fonts.googleapis.com/css?family=Istok+Web:400,700
standalone = 1
external = 1
}
styles {
type= css
name = main-style
path = EXT:my_template/Resources/Public/css/main.css
standalone = 1
}
}
现在扩展中的一些CSS文件会被压缩,但是我通过vhs.asset添加的文件根本不会被压缩。
知道为什么压缩不适用于通过vhs.asset添加的CSS(和JS)?
答案 0 :(得分:1)
虽然TYPO3 CMS中存在这样的选项,但它不是CMS工作,而是服务器的工作(Apache,nginx等)。
所以,如果你有一个nginx服务器,它可以通过以下配置来完成(可能已经在/etc/nginx/nginx.conf
中打开了):
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/html text/xml text/css text/javascript application/json application/xml application/xml+rss application/x-javascript;
对于Apache,您需要mod_deflate
中的.htaccess
及以下行:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xml+rss
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
好处:
link
或style
标记链接 - 它们将始终被压缩; 压缩数据的大小在两种情况下都是相同的(当然,还取决于压缩级别设置),因为使用了相同的库和算法。
答案 1 :(得分:0)
试试这个以包含你的css / js:
#-------------------------------------------------
# Distribution Configuration/TypoScript/setup.ts
#-------------------------------------------------
page = PAGE
page {
# CSS files to be included
includeCSS {
myTemplate = EXT:my_template/Resources/Public/Css/main.css
}
# JS to be included (mind how other JS is included)
# includeJSFooter is also very common
includeJS {
myTemplate = EXT:my_template/Resources/Public/JavaScript/script.js
}
}
(ps:在这种情况下你必须包括你的静态模板)