A
A
aleksandrtom2019-12-29 15:43:05
caching
aleksandrtom, 2019-12-29 15:43:05

I wrote a website html/css/js, put it on hosting, what about caching?

I wrote the site, uploaded it to the hosting, checked it on PageSpeed ​​Insights, saw that I needed to enable caching, I was told that caching is done manually VERY hard and advised to put the site on the WordPress engine and install the plugin, but no matter how the site was thought about it. But I installed , connected the plugin, but the site is not cached. Then I read about connecting caching to the site on html / css, it turned out that everything is easy to do there through .htaccess.
The question is, can I just upload my layout to the hosting, configure caching via .htaccess and that's it? Will the site work and there will be no problems/difficulties in the future?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
Dmaw, 2019-12-29
@aleksandrtom

Add this to htaccess:

<ifModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>

<IfModule mod_gzip.c>
  mod_gzip_on         Yes
  mod_gzip_dechunk    Yes
  mod_gzip_item_include file		\.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include mime		^text\.*
  mod_gzip_item_include mime		^application/x-javascript.*
  mod_gzip_item_include mime		^application/javascript.*
  mod_gzip_item_exclude mime		^image\.*
  mod_gzip_item_exclude rspheader	^Content-Encoding:.*gzip.*
</IfModule>

<ifModule mod_headers.c>
    <filesMatch "\.(ico|jpg|jpeg|png|gif|swf)$">
        Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(css)$">
        Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(js)$">
        Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(x?html?|php)$">
        Header set Cache-Control "private, must-revalidate"
    </filesMatch>
</ifModule>

<ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access 7 days"
    ExpiresByType image/x-icon "access plus 6 month"
    ExpiresByType image/jpeg "access plus 6 month"
  ExpiresByType image/jpg "access plus 6 month"
    ExpiresByType image/png "access plus 6 month"
    ExpiresByType image/gif "access plus 6 month"
    ExpiresByType application/x-shockwave-flash "access plus 6 month"
    ExpiresByType text/css "access plus 7504800 seconds"
    ExpiresByType text/javascript "access plus 7516000 seconds"
    ExpiresByType application/javascript "access plus 7516000 seconds"
    ExpiresByType application/x-javascript "access plus 7516000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>

F
Froggyweb, 2019-12-29
@Froggyweb

The question is, can I just upload my layout to the hosting, configure caching via .htaccess and that's it? the site will work and there will be no problems/difficulties in the future?

you may not even cache at all. There won't be any problems for sure. Especially if everything is set up normally and pictures of 5 MB each are not loaded. pagespeed warnings can sometimes be ignored if you know what you're doing.
this is bullshit for you

Z
ZoomLS, 2020-01-02
@ZoomLS

advised to put the site on the wordpress engine

Who is giving you such bad advice? If you put Wordpress - it will only get worse.

A
Andrey, 2019-12-29
@VladimirAndreev

The website is html/css/js files? Just put it on the hosting, the web server will cache everything

M
Martovitskiy, 2019-12-29
@Martovitskiy

cloudflare

X
xmoonlight, 2020-12-30
@xmoonlight

Don't listen to anyone's advice!
1. Read about caching yourself
2. Adjust according to the documentation
3. Check with Google PageSpeed ​​Insights .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question