S
S
Sergey2021-07-09 09:52:04
1C-Bitrix
Sergey, 2021-07-09 09:52:04

How not to cache a static page on Bitrix?

Good afternoon.

There is a static page on Bitrix, a css and js script is connected to it.
This page is heavily cached, we make any changes to css or js and do not see the changes.

Tell me, how can I remove the cache immeno to the page or to these 2 scripts?

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2021-07-09
@oldzas

If it is inserts into html code, then the
easiest option is to add a random string to the link to js and css.
Example

<script src="test.js?random=<?php echo uniqid(); ?>"></script>

But this is not the right way to connect scripts and styles in Bitrix, you need to connect like this
Example
use Bitrix\Main\Page\Asset;

Asset::getInstance()->addJs(SITE_TEMPLATE_PATH . "/js/fix.js");
Asset::getInstance()->addCss(SITE_TEMPLATE_PATH . "/styles/fix.css");
Asset::getInstance()->addString("<link href='http://fonts.googleapis.com/css?family=PT+Sans:400&subset=cyrillic' rel='stylesheet' type='text/css'>");

Then you can reset the cache in the admin panel or on the desired page on the administration panel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question