How to compress and optimise an Angular2 application

前端 未结 2 675
粉色の甜心
粉色の甜心 2020-12-07 07:28

I want to make my angular-cli application faster!

Right, so I have spent a number of days updating my NG2 application to work with angular-cli. At first i

2条回答
  •  难免孤独
    2020-12-07 07:58

    For those interested in the HTACCESS file I am using, here it is. This does force https which slows things down by about 100ms:

    #REDIRECT ROUTES TO INDEX (fixes broken routes with angular)
    RewriteEngine on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) /index.html [NC,L]
    #ENABLE GZIP COMPRESSION TO IMPROVE PERFORMANCE
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    # SET EXPIRE HEADERS TO IMPROVE PERFORMANCE
    
      ExpiresActive On
      ExpiresDefault "access plus 2 days"
      ExpiresByType image/x-icon "access plus 1 year"
      ExpiresByType image/jpeg "access plus 1 year"
      ExpiresByType image/jpg "access plus 1 year"
      ExpiresByType image/png "access plus 1 year"
      ExpiresByType image/gif "access plus 1 year"
      ExpiresByType application/x-shockwave-flash "access plus 1 month"
      ExpiresByType text/css "access plus 1 month"
      ExpiresByType text/javascript "access plus 1 month"
      ExpiresByType application/pdf "access plus 1 month"
      ExpiresByType application/javascript "access plus 2 week"
      ExpiresByType application/x-javascript "access plus 2 week"
      ExpiresByType text/javascript "access plus 2 week"
      ExpiresByType text/html "access plus 600 seconds"
      ExpiresByType application/xhtml+xml "access plus 600 seconds"
    
    # END Expire headers
    # BEGIN Cache-Control Headers
    
      
        Header set Cache-Control "public"
      
      
        Header set Cache-Control "public"
      
      
        Header set Cache-Control "public"
      
      
        Header set Cache-Control "private, must-revalidate"
      
    
    # END Cache-Control Headers
    

提交回复
热议问题