These are two separate issues actually, but they are addressed by the same feature in
JCH Optimize
by adding appropriate directives in the .htaccess file in the root
of the site using the Optimize .htaccess button in the
Utility Tasks
section on
The Dashboard
.

Text-based resources should be served with compression to minimize total network bytes. Compression is the process of modifying data using a compression algorithm to reduce overall file size. Compressing files can significantly improve the performance of the website.
JCH Optimize
leverages the server's filter module to dynamically compress static files by using the
AddOutputFilterByType
directive. Two compression algorithms are supported, Gzip, a widely used compression
format for server and client interactions, or Brotli, a newer compression algorithm
which can provide even better compression results than Gzip. If Brotli is supported by
the server then Brotli will be used, otherwise Gzip will be used.
HTTP caching can speed up your page load time on repeat visits. When a browser requests a resource, the server providing the resource can tell the browser how long it should temporarily store or cache the resource. For any subsequent request for that resource, the browser uses its local copy rather than getting it from the network.
The directives added to the .htaccess file directs the server to
return the Cache-Control HTTP response header and uses the
ExpiresByType
to indicate what how long a resource should be cached by the browser.
The following codes are added to the .htaccess file by
JCH Optimize
to enable text compression and serve static assets with an efficient cache
policy:
## BEGIN EXPIRES CACHING - JCH OPTIMIZE ##
<IfModule mod_expires.c>
ExpiresActive on
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# Feed
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 year"
# Webfonts
ExpiresByType application/font-ttf "access plus 1 year"
ExpiresByType font/* "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType type/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
<IfModule mod_brotli.c>
<IfModule mod_filter.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/xml text/plain
AddOutputFilterByType BROTLI_COMPRESS application/rss+xml application/xml application/xhtml+xml
AddOutputFilterByType BROTLI_COMPRESS text/css
AddOutputFilterByType BROTLI_COMPRESS text/javascript application/javascript application/x-javascript
AddOutputFilterByType BROTLI_COMPRESS image/x-icon image/svg+xml
AddOutputFilterByType BROTLI_COMPRESS application/rss+xml
AddOutputFilterByType BROTLI_COMPRESS application/font application/font-truetype application/font-ttf
AddOutputFilterByType BROTLI_COMPRESS application/font-otf application/font-opentype
AddOutputFilterByType BROTLI_COMPRESS application/font-woff application/font-woff2
AddOutputFilterByType BROTLI_COMPRESS application/vnd.ms-fontobject
AddOutputFilterByType BROTLI_COMPRESS font/ttf font/otf font/opentype font/woff font/woff2
</IfModule>
</IfModule>
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/xml text/plain
AddOutputFilterByType DEFLATE application/rss+xml application/xml application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/font application/font-truetype application/font-ttf
AddOutputFilterByType DEFLATE application/font-otf application/font-opentype
AddOutputFilterByType DEFLATE application/font-woff application/font-woff2
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf font/otf font/opentype font/woff font/woff2
</IfModule>
</IfModule>
# Don't compress files with extension .gz or .br
<IfModule mod_rewrite.c>
RewriteRule "\.(gz|br)$" "-" [E=no-gzip:1,E=no-brotli:1]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(gz|br)$ no-gzip no-brotli
</IfModule>
</IfModule>
## END EXPIRES CACHING - JCH OPTIMIZE ##
These codes are also added and updated whenever the package is installed or the component is updated.