Skip to content

How to use build_fingerprint #185

@tiagoslg

Description

@tiagoslg

Hi,

I'm kind of new in React, but when I was trying to load de Demo 6, Django wasn't able to find some of the static files. After some time looking for the code, I rewrite the function "_collect_and_register_resources", originally from Dash package to a new one that ignore the call "build_fingerprint". After that, Django was able to find the static files, and load the example as expected.

I put the method inside class WrappedDash(Dash)

`

    class WrappedDash(Dash):

    ...

        def _collect_and_register_resources(self, resources):
            # now needs the app context.
            # template in the necessary component suite JS bundles
            # add the version number of the package as a query parameter
            # for cache busting
            def _relative_url_path(relative_package_path="", namespace=""):
                module_path = os.path.join(
                    os.path.dirname(sys.modules[namespace].__file__),
                    relative_package_path,
                )
                modified = int(os.stat(module_path).st_mtime)
                return "{}_dash-component-suites/{}/{}".format(
                    self.config.requests_pathname_prefix,
                    namespace,
                    relative_package_path
                )
            srcs = []
            for resource in resources:
                is_dynamic_resource = resource.get("dynamic", False)
                if "relative_package_path" in resource:
                    paths = resource["relative_package_path"]
                    paths = [paths] if isinstance(paths, str) else paths
                    for rel_path in paths:
                        self.registered_paths[resource["namespace"]].add(rel_path)
                        if not is_dynamic_resource:
                            srcs.append(
                                _relative_url_path(
                                    relative_package_path=rel_path,
                                    namespace=resource["namespace"],
                                )
                            )
                elif "external_url" in resource:
                    if not is_dynamic_resource:
                        if isinstance(resource["external_url"], str):
                            srcs.append(resource["external_url"])
                        else:
                            srcs += resource["external_url"]
                elif "absolute_path" in resource:
                    raise Exception(
                        "Serving files from absolute_path isn't supported yet"
                    )
                elif "asset_path" in resource:
                    static_url = self.get_asset_url(resource["asset_path"])
                    # Add a cache-busting query param
                    static_url += "?m={}".format(resource["ts"])
                    srcs.append(static_url)
            return srcs

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions