switch to the spare cdn address when the cdn resource of the unpkg fails
Open
Nobody has claimed this yet.
feature
P3
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
My current solution is as below:
class CustomDash(dash.Dash):
def interpolate_index(self, **kwargs):
scripts = kwargs.pop('scripts')
external_scripts = re.findall(
'(<script src="http.*?"></script>)', scripts)
for external_script in external_scripts:
scripts = scripts.replace(
external_script,
'''<script src="{}" onerror='this.remove(); let fallbackScript = document.createElement("script"); fallbackScript.src = "{}"; document.querySelector("footer").appendChild(fallbackScript);'></script>'''.format(
re.findall('"(.*?)"', external_script)[0]
.replace('https://unpkg.com/', 'https://unpk.com/'), # Manually simulated unpkg resource loading failure error
re.findall('"(.*?)"', external_script)[0]
.replace('https://unpkg.com/', 'https://npm.elemecdn.com/') # Switch to standby address
)
)
return super(CustomDash, self).interpolate_index(scripts=scripts, **kwargs)
but it meets the Uncaught ReferenceError: DashRenderer is not defined error:
is there a stable way to solve this issue🤔?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CustomDash.interpolate_index override shown in the issue and trace how Dash assembles external scripts and DashRenderer. Reproduce the unpkg failure and the resulting “DashRenderer is not defined” error, then verify that a stable fallback loads all required resources without that error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, python
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100