question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More aggressively cache/pre-fetch events from AJAX calls

See original GitHub issue

Originally reported on Google Code with ID 1822

Hello,

Maybe I understand lazyFetching wrong or I remember it working wrong, but from what
I recall if I had this lazyFetching set to true (by default) and switched weeks in
weekAgenda view, calendar fetched each week only once. Right now it fetches weeks all
the time (when I switch back and forth). Shouldn't it keep events in memory?

Kind regards,
Mike

Reported by koniczynek on 2013-05-04 19:58:51

Imported with 8 stars.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
mattclarcommented, Oct 13, 2016

could I suggest an implementation such as having a lazyFetchDays: paramater that fetches x days ahead and behind the current, that way scrolling between days becomes smoother because the cache already has the days prefetched. You would probably set the default to 0 days just so as not to change behaviour

2reactions
mattclarcommented, Feb 17, 2017

I have written my own caching method to get around this limitation, its pretty simple to implement in your code, I haven’t quite written the initial bit which aims to pull the event data from the page to speed the initial load. Then it does an ajax request and stores the results for the rendered day +/- 3 days in the cache, further calls to the method hut the cache first and also trigger a reload of the cache advancing it along so you always have a buffer of three days to supply to the calendar. This is appropriate for my needs…hope it helps others too. PS sorry its in coffescript the autotranscribed js was ugly

    $('#calendar').fullCalendar events: (start, end, timezone, callback) ->
        eventsProvided = false
        if isInitialLoad is true
          #find events in page
        else
          if moment(start).isSameOrAfter(apptCacheStart) and moment(end).isSameOrBefore(apptCacheEnd)
            callback appointmentsCache
            eventsProvided = true

        $.ajax
          url: '/appointments.json'
          dataType: 'json'
          data:
            start: start.subtract(3, 'days').toISOString()
            end: end.add(3, 'days').toISOString()
          success: (events) ->
            isInitialLoad = false
            apptCacheStart = start.subtract(3, 'days')
            apptCacheEnd = end.add(3, 'days')
            appointmentsCache = []
            appointmentsCache = appointmentsCache.concat events
            if eventsProvided isnt true 
              callback appointmentsCache
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid too many ajax calls and cache json data on the ...
I have a calendar application and it loads all of the event data using ajax and json results. the issue is that i...
Read more >
5 Ways to Improve Your Ajax Performance - Peachpit
The first goal isn't to cut out all Ajax requests, but the unnecessary ones. Or, if you want to be aggressive, also cut...
Read more >
Ajax Events | jQuery API Documentation
Ajax requests produce a number of different events that you can subscribe to. Here's a full list of the events and in what...
Read more >
Handling Sequential AJAX Calls using jQuery
There is a requirement to make multiple AJAX calls parallelly to fetch the ... callback functions based on zero or more Thenable objects, ......
Read more >
What can go wrong if you make synchronous Ajax calls using ...
Synchronous API call means Javascript thread will stop further execution of ... The answer lies in how Event loop handles task (callback) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found