GordonLesti / Lesti_Fpc

Simple Magento Fullpagecache
https://gordonlesti.com/lesti-fpc-documentationversion-1-4-5/
Other
358 stars 159 forks source link

Question on javascript cache #298

Closed gety9 closed 7 years ago

gety9 commented 7 years ago

Please head me in the right direction:

On our page we have custom booking extension that uses inlined javascript to control tour availability for different days and time options.

Since all block is same, it's only js variables that change, i would prefer to keep cache for the block, and not cache only js part.

What's the right way to do it?

Here is part of js, these vars are the ones that changing (the var arrays are much longer, it's just shorter version):

function adjustBeforeShowDay(date) {
        var soldoutDates = ["2017-06-08","2017-06-19","2017-06-22"];
        var lowAvaiDates = ["2017-06-16","2017-06-20","2017-06-24"];
            ....
            some code here
            ....
}

jQuery(document).ready(function($) {
        var notavai_values = jQuery.parseJSON('{"2017-06-11":["5:00 PM"],"2017-06-12":["1:00 PM"],"2017-06-13":["4:00 PM"]}');
        var soldout_values = jQuery.parseJSON('{"2017-06-11":["1:00 PM"],"2017-06-12":["3:00 PM"],"2017-06-13":["2:00 PM"]}');
        var lowavai_values = jQuery.parseJSON('null');
        var soldout_interval = 6;
            ....
            some code here
            ....
}

They are taken from database table which is updated every time order is made. Should we somehow make the js dynamic/lazy and update it everytime order is made?

Or should we put the inlined js in external js file? (would it prevent FPC from caching it?)

GordonLesti commented 7 years ago

Hello @gety9 unfortunately FPC comes to its limits if you have dynamic data that is binded to a product or stock model. If you have not so often orders, a possible solution would be cleaning FPC product specific. An other solution is to load those data via AJAX in my eyes.

gety9 commented 7 years ago

@GordonLesti

Thank you for AJAX suggestions, As far as i understand AJAX is the way it should be implemented in the first place, correct? (checked common booking platforms such as fareharbor, and they load all availability data using json)