Hi,
Well, I've spent my morning on this.
To remove the javascript error, I actually had to make the code a lot more complex.
Here is what I've come up with instead of what I had told you:
new Promise((resolve, reject)=>{
var script = d.createElement('script');
script.setAttribute('type', 'text/javascript');
var windowErrorHandler = (event) =>{
event.preventDefault();
var error = event.error;
error.stack = error.stack + '\n\n' + scripts;
window.removeEventListener('error', windowErrorHandler);
reject(error);
};
window.addEventListener('error', windowErrorHandler);
var rejectHandler = (error) =>{
window.removeEventListener('error', windowErrorHandler);
reject(error);
};
script.addEventListener('error', rejectHandler);
script.addEventListener('abort', rejectHandler);
var loadedHandler = ()=>{
window.removeEventListener('error', windowErrorHandler);
resolve();
};
script.addEventListener('load', loadedHandler);
script.text = scripts.replaceAll('let jch_', 'jch_').replaceAll('const jch', 'window.hikashop.jch');
try {
d.head.appendChild(script);
d.head.removeChild(script);
} catch (e) {
if (e instanceof SyntaxError) {
}
}
})
.catch(error => {
console.warn('Could not process JavaScript code:\n', error);
})
.then(()=>{
});
This does two things:
- it catches errors generated by scripts loaded in AJAX and cancel them so that the infinite scroll system can continue its job
- it prevents the errors in the JCH Optimize script
However, it's still not working with the "enable combine files" setting of JCH Optimize activated.
While the error didn't help, it's not the main issue I think. The issue I think is that JCH is using cached JS in the AJAX request instead of using the new JS inlined by the infinite scroll mechanism to give to the JS already loaded the new URL to use which includes the values of the filters. So the mechanism calls on the following pages of the infinite scroll as if no filter was set.
Ideally, if JCH Optimize would have some mechanism we could use to tell it to not cache some piece of inlined JS, it would be great.
For example, in the file components/com_hikashop/views/product/tmpl/listing_div.php there are 3 times the line:
<script type="text/javascript">
If we could change them to:
<script type="text/javascript" data-nocache>
and JCH Optimize would skip these, it should solve the problem.
Could you please convey all this to the JCH Optimize support person you were talking to and see what they propose ?