使用Polymer 1.7.0.2库的网页突发故障求助
Hey there, let's break down your issue and walk through actionable fixes to get your pages displaying properly again.
First, let's recap the core problem you're facing:
- Your site’s pages are failing to load elements correctly after migrating from the old rawgit CDN to jsdelivr
- Most Polymer resources redirect properly via 301, but two indirectly imported libraries (
polymer-micro.htmlandpaper-ripple-behavior.html) return a 200 status code with empty content - These two libraries aren’t directly included in your page—they’re pulled in by other Polymer components you’re using
- Your page still references the old rawgit CDN for direct imports, and you’re seeing CORS-related warnings in the console
Here are the steps to resolve this:
1. Replace All Direct CDN Imports with the New jsdelivr URL
The 301 redirects from rawgit to jsdelivr might be causing issues with Polymer’s HTML import system, especially for indirect dependencies. By switching all your direct imports to use the new jsdelivr URL directly, you eliminate the redirect step and ensure all resources (including indirect ones) are fetched from the correct source.
Your current direct imports use this prefix:
https://cdn.rawgit.com/download/polymer-cdn/1.7.0.2/
Replace it with the new jsdelivr prefix for every <link rel="import"> tag pointing to the CDN. For example:
Before:
<link href="https://cdn.rawgit.com/download/polymer-cdn/1.7.0.2/lib/iron-flex-layout/iron-flex-layout-classes.html" rel="import">
After:
<link href="https://cdn.jsdelivr.net/gh/download/polymer-cdn@1.7.0.2/lib/iron-flex-layout/iron-flex-layout-classes.html" rel="import">
Update all 10 of your CDN-hosted Polymer imports to use this new prefix.
2. Explicitly Import the Problematic Libraries
Since polymer-micro.html and paper-ripple-behavior.html are being pulled in indirectly, their failed loading might be due to the redirect chain breaking the import resolution. Add these two libraries as direct imports at the top of your page (before other Polymer imports) to ensure they load correctly:
<!-- Add these first to ensure they're loaded before dependent components --> <link href="https://cdn.jsdelivr.net/gh/download/polymer-cdn@1.7.0.2/lib/polymer/polymer-micro.html" rel="import"> <link href="https://cdn.jsdelivr.net/gh/download/polymer-cdn@1.7.0.2/lib/paper-ripple/paper-ripple-behavior.html" rel="import"> <!-- Your existing imports (updated to jsdelivr) go here --> <link href="qliksense-card.html" rel="import"> <link href="https://cdn.jsdelivr.net/gh/download/polymer-cdn@1.7.0.2/lib/iron-flex-layout/iron-flex-layout-classes.html" rel="import"> <!-- ... rest of your imports ... -->
3. Verify CORS Settings (If Issues Persist)
While jsdelivr typically has permissive CORS settings, if you still see CORS warnings after updating the URLs, check your page’s Content-Security-Policy (CSP) headers. Ensure they allow loading resources from cdn.jsdelivr.net. If you don’t control the server headers, you can also check the browser console’s exact CORS error message to pinpoint which resource is blocked—but since you can’t share site access, starting with steps 1 and 2 should resolve the empty content issue first.
Why This Happens
Rawgit's 301 redirects can interfere with Polymer’s HTML import system, which relies on consistent, immediate access to resource content. Even though the redirect leads to the correct jsdelivr location, the indirect import resolution might fail to handle the redirect properly, resulting in empty responses for those two critical libraries. By using the new URL directly, you bypass this redirect and ensure reliable loading.
内容的提问来源于stack exchange,提问作者Benjamin schwarz

