panel.io.resource_spec module#
Derives the client-side resource specification for component classes.
The specification is the payload the browser needs in order to load a
component’s external libraries on demand. It is derived entirely from the
declarations components already make (__javascript_raw__,
__javascript_modules_raw__, __javascript_module_exports__,
__css_raw__ and __js_skip__), so third-party component authors get
lazy loading without any new API.
The same specification feeds both delivery paths:
the lazy path, where it is carried by the
external_resourcesproperty of a model instance and resolved by the client-side registry, andthe eager path, where
pn.extensionrenders the script and link tags into the page and the templates calldeclare()on the registry with the specs it just satisfied.
Generating both from one function is what keeps them from drifting.
- panel.io.resource_spec.declared_specs(mode: MODES | None = None) dict[str, t.Any][source]#
The resources the eager path has already satisfied.
Rendered into the page (and the notebook bootstrap) as a
declare()call so that the registry knows about them without having to infer it from the DOM, which is the only thing that works ininlinemode, where the libraries were inlined and have no urls at all.
- panel.io.resource_spec.lazy_load_available(notebook: bool = False) bool[source]#
Whether a component that was not declared can still get its resources.
False when lazy loading was switched off, and for self-contained
inlineoutput, where there is nothing left to inline after the fact and the component would silently fall back to the CDN. Notebooks are exempt from the latter: their output is never self-contained anyway.
- panel.io.resource_spec.resource_spec(cls: type, mode: MODES | None = None) dict[str, t.Any] | None[source]#
Builds the client-side resource specification for a component class.
Groups the class’
__javascript__urls by the global they provide (from__js_skip__), resolves them for the active resource mode via the samebundled_files/adjust_pathsmachinery the eager path uses, and appends__javascript_modules__(with their__javascript_module_exports__names) and__css__.- Parameters:
- cls: type
A Bokeh model class, or a
ReactiveHTML/ReactiveESMsubclass, whose resources are declared on the Panel class.- mode: MODES | None
Resource mode to resolve urls for, defaulting to the active one.
- Returns:
- The specification, or None if the class declares no resources or lazy
- loading is disabled.