Skip to content

Commit

Permalink
Optimize preload
Browse files Browse the repository at this point in the history
  • Loading branch information
magiccart committed Apr 19, 2021
1 parent 4fa2909 commit 948a245
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
</field>
<field id="crisp_website_id" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Crisp website Id</label>
<comment><![CDATA[You can find ID follow guide <a href="https://help.crisp.chat/en/article/how-to-find-the-website-id-1ylqx1s/">Visit here!</a> or Register an account <a href="https://crisp.chat/">here!</a> ]]></comment>
<depends><field id="zoomType" separator=",">window</field></depends>
<comment><![CDATA[You can find ID follow guide <a href="https://help.crisp.chat/en/article/how-to-find-the-website-id-1ylqx1s/">visit here!</a> or register an account <a href="https://crisp.chat/">here!</a> ]]></comment>
</field>
<field id="no_js" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enabled mode no-js</label>
Expand Down
15 changes: 13 additions & 2 deletions view/frontend/templates/crisp.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
$helper = $this->helper('Magepow\Crispchat\Helper\Data');
$crispWebsiteId = $helper->getConfigModule('general/crisp_website_id');
if(!$crispWebsiteId) return;
$noJs = $helper->getConfigModule('general/no_js');
?>
<script type="text/javascript">
<?php if(!$noJs) : ?>
<link rel="preload" href="https://client.crisp.chat/l.js" as="script">
<script type="text/javascript">
require(['jquery'], function($){
"use strict";
window.$crisp=[];window.CRISP_WEBSITE_ID="<?php echo $crispWebsiteId ?>";(function(){let d=document; let s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();
});
</script>
<? else : ?>
<script type="text/javascript">
require(['jquery'], function($){
"use strict";
$("body").one("mousemove", function() {
window.$crisp=[];window.CRISP_WEBSITE_ID="<?php echo $crispWebsiteId ?>";(function(){let d=document; let s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();
});
});
</script>
</script>
<?php endif ?>

0 comments on commit 948a245

Please sign in to comment.