Feature Request: Add an API for Notifying Attachment Updates to Enable Partial Updates in Obsidian

I am currently working on a plugin that tracks and updates attachments externally, but I’ve run into a limitation. While my plugin is able to detect and manage attachment updates, Obsidian itself does not recognize these changes automatically. This means that the attachments aren’t updated in the viewer, and the files don’t sync as expected.

Currently, I know that it’s possible to trigger a full re-render of the Markdown preview using MarkdownPreviewView.rerender(). However, this approach doesn’t seem ideal for my use case. Triggering a full rerender causes the scroll position of the viewer to shift, which is disruptive for the user experience.

It would be incredibly useful if there were an API function, something like notifyAttachmentChanged, which could notify Obsidian about attachment updates, allowing the app to refresh the relevant part of the view without affecting the entire document. This would enable partial updates of attachments and avoid the need for re-rendering the entire preview.

I believe this feature would improve the experience for plugin developers and users alike, making Obsidian more responsive to external changes in attachments.

You can achieve this functionality manually.

  1. on('modify') - Developer Documentation

Gets triggered when your attachment files changed.

  1. Then you need to find all backlinks of that attachments. There is no function in public Obsidian API but there is an internal one. However it’s not efficient on huge vaults. I have a plugin GitHub - mnaoumov/obsidian-backlink-cache: Obsidian Plugin that stores backlink cache to speed up app.metadataCache.getBacklinksForFile() to improve that.

  2. Regarding refreshing and keeping the scroll position, look at my other plugin GitHub - mnaoumov/obsidian-refresh-any-view: Obsidian Plugin that allows to refresh preview mode without reopening the note

Thanks again for your suggestions!

At the moment, I’ve settled on batching attachment updates and triggering a preview refresh afterward—it works decently well for now.

That said, I still feel that since Obsidian is already capable of detecting newly created files (e.g. when attachments are first added and displayed), it should ideally also be able to detect and respond to changes in those same files—just like how a browser automatically updates an image when its source file is modified.

In other words, attachment updates feel like they should be naturally handled by the system without needing full rerenders or manual refresh logic from plugins.

Still, I appreciate the work you’ve done—your plugins offer valuable tools to bridge the gap in the meantime!

I’ve found a solution that works quite well for now. By inspecting the HTML rendered by the Obsidian previewer, I noticed that image links include a query parameter representing the last modified timestamp—something like ?1753338513903. This effectively acts as a cache-busting mechanism.

So whenever I update an attachment (like an image), I simply update that timestamp parameter, and the image refreshes automatically in the preview. It feels like a natural workaround that aligns with how browsers handle resource updates, and it avoids the need for a full re-render or manual intervention.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.