2

I'm really curious if someone can better explain the internal workings of excel's addin caching of javascript functions? I'm running a flask app on my own internal website behind a SSL cert. My addin pulls in this functionfile.html, and makes an ajax call back to mysite:

<script>
// After the Office library builds, it will look for Office.initialize
// which must be passed a function.  It doesnt have to do anything though.
    Office.initialize = function (reason){
        $(document).ready(function(){
            registerBindings();
        });
    }


    function getData(){
        return Excel.run( function (context) {

            // request bindings
            var state_nbr = context.workbook.bindings.getItem("state_nbr").getRange().load("values");
            // and the rest for the ajax call

            return context.sync().then( function () {
                $.ajax({
                  type: "GET",
                  url: "https://example.com/excel/function",
                  data: {
                      "state_nbr": state_nbr.values[0][0]
                  }
              }).done( function (data){
                      context.workbook.bindings.getItem("test").getRange().values = [["done"]];
                      return context.sync();
              }).fail( function (result){
                      context.workbook.bindings.getItem("test").getRange().values = [["fail"]];
                      return context.sync();
              });
          });
      });
   }
</script>

When I click my button, I can see the request with the right payload going to example.com/excel/function, which is a flask route that pumps out a bunch of CLI junk (hundreds of logging commands).

What gets weird though, is that after that first click every time I click the button I don't get any new ajax requests, I only get a request for the functionfile.html. But SheetA1 still pops up "done".

I thought this was just storing the results in cache, but even with flask running in debug mode, if I change functionfile.html, say [["done"]] to [["finished"]], no new ajax call is detected in my logs. BUT THE SHEET UPDATES?!

Tony
  • 1,318
  • 1
  • 14
  • 36
  • 1
    Could you install the Fiddler tool from https://www.telerik.com/fiddler. In some circumstances, if the server gets a request for something it has sent before and that something hasn't changed, it will return a 304 message instead of resending the data. It might be helpful to know if you're getting 304 when you click the button a 2nd time. – Rick Kirkham Jan 19 '18 at 20:38
  • Maybe this is a question for a different tag then, but if I change the data this makes a new call. The first time. No matter how long I wait I never get a new one back. So I took it step farther and closed my workbook and now the same request data will make a new call. Does the server recognize different workbooks as different clients? – Tony Jan 19 '18 at 21:05
  • And is there a name for server's caching same requests, I need to set it to zero so I can do some JSON parsing testing. – Tony Jan 19 '18 at 21:06
  • 1
    See this SO post for how to turn off caching in an ajax request: https://stackoverflow.com/questions/4303829/how-to-prevent-a-jquery-ajax-request-from-caching-in-internet-explorer For your other question, I *think* that closing the workbook would unload the functionfile.html. If that's right then pressing the button again with a different, or reloaded, workbook would load a new instance of functionfile.html and start a new session with the server. – Rick Kirkham Jan 21 '18 at 07:47

0 Answers0