Automatic and Manual Syncing

By default, PSPDFKit Instant automatically synchronizes changes with your PSPDFKit Server in real time. This is configurable, so you can instead choose for it to sync manually.

The network is a limited resource. While we do our best to minimize network usage of Instant, it can be reduced further by disabling listening for changes from the server or by syncing less often after local changes are made.

Saving to the server after making local changes and listening for server changes are things that can be configured separately. However, saving always sends all local changes to and fetches all changes from the server. It is not possible to fetch remote changes without pushing local changes or to push local changes without fetching remote changes.

ℹ️ Note: We don’t recommend combining disabled auto-save and enabled listening for server changes, as doing so could result in pushing local changes at seemingly random times when changes are received from the server.

Disabling Listening for Server Changes

All you have to do to disable automatic fetching of server changes is to configure listenToServerChanges in the Instant settings object to false:

PSPDFKit.load({
    instant: {
        listenToServerChangesEnabled: false
    },
    ...
});
PSPDFKit.load({
    instant: {
        listenToServerChangesEnabled: false
    },
    ...
});

Then sync manually whenever needed by calling PSPDFKit.Instance#save:

// Make local changes.
await instance.create(annotation);
...

// Now the changes get saved and all remote changes are pulled.
await instance.save();
// Make local changes.
instance
  .create(annotation)
  // ...
  // Now the changes get saved and all remote changes are pulled.
  .then(instance.save)
  .then(function() {
    console.log("Changes saved");
  });

Disabling Syncing Local Changes

In addition to disabling listening for changes from the server (mentioned above), you can control when the local changes are saved. If nothing else is configured, PSPDFKit for Web will have auto-save enabled. This means that changes are automatically synced. You can use Configuration#autoSaveMode to configure exactly when changes are saved.

You can disable automatic saving of local changes by specifying AutoSaveMode.DISABLED:

PSPDFKit.load({ autoSaveMode: PSPDFKit.AutoSaveMode.DISABLED, ... });
PSPDFKit.load({ autoSaveMode: PSPDFKit.AutoSaveMode.DISABLED, ... });

You can then use PSPDFKit.Instance#save to trigger a save manually whenever you want.

Read more about other options for auto-save mode in our Saving Mechanism guide.