Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing CDN provider by user to solve problem where default CDN is blocked countrywise #12120

Open
cderv opened this issue Feb 19, 2025 · 2 comments
Labels
enhancement New feature or request html Issues with HTML and related web technology (html/css/scss) ojs-engine Issues with the ojs engine search
Milestone

Comments

@cderv
Copy link
Collaborator

cderv commented Feb 19, 2025


Discussed in #12109

Originally posted by skyfroger February 18, 2025

Description

I have issues reaching cdn.jsdelivr.net in my country. So I am getting errors while trying to render MathJax formulast and inster OJS interactive elements. Is there are an option to change default CDN provider?


Context

I believe Quarto should try to be friendly as possible with users wherever they are. Currently, cdn.jsdelivr.net is used by default in several places

Mathjax / KaTeX

const math = format.pandoc[kHtmlMathMethod];
if (math === undefined || math === "mathjax") {
return {
method: "mathjax",
url: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js",
};
} else if (math === "katex") {
return {
method: "katex",
url: "https://cdn.jsdelivr.net/npm/[email protected]/dist/",
};

This one can already be customized through html-math-method configuration by providing a full new URL

Search with Algolia

It is using cdn.jsdelivr.net by default with no customization

function autocompleteInsightsPluginScript(cookieConsent: boolean) {
return scriptTagWithConsent(
cookieConsent,
"tracking",
"",
"https://cdn.jsdelivr.net/npm/@algolia/autocomplete-plugin-algolia-insights",
);
}
function algoliaSearchInsightsScript(cookieConsent: boolean) {
return scriptTagWithConsent(
cookieConsent,
"tracking",
`var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights/dist/search-insights.iife.min.js";
!function(e,a,t,n,s,i,c){e.AlgoliaAnalyticsObject=s,e[s]=e[s]||function(){
(e[s].queue=e[s].queue||[]).push(arguments)},i=a.createElement(t),c=a.getElementsByTagName(t)[0],
i.async=1,i.src=n,c.parentNode.insertBefore(i,c)
}(window,document,"script",ALGOLIA_INSIGHTS_SRC,"aa");`,
);
}
const kAlogioSearchApiScript =
`<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js"></script>
`;

OJS

Note

EDIT: For OJS this is not possible as we inherit from ObservableHQ directly (#12120 (comment))

I see

function resolveFrom(origin = "https://cdn.jsdelivr.net/npm/", mains = ["unpkg", "jsdelivr", "browser", "main"]) {
if (!/\/$/.test(origin)) throw new Error("origin lacks trailing slash");

which probably is related to how NPM package are served: https://quarto.org/docs/interactive/ojs/libraries.html#npm

This is the real problem encountered in #12109

This would be another part to make it configurable if possible 🤷‍♂

Current workaround

Currently doing a post processing to replace the CDN used in quarto-os-runtime.js or other file

@cderv cderv added enhancement New feature or request html Issues with HTML and related web technology (html/css/scss) ojs-engine Issues with the ojs engine search labels Feb 19, 2025
@cderv cderv added this to the Future milestone Feb 19, 2025
@cscheid
Copy link
Collaborator

cscheid commented Feb 19, 2025

We don't fully control this, unfortunately. This is coming from the ObservableHQ source code directly. We would have to fork their implementation and maintain the option forever. I don't think we can afford to do that.

@cderv
Copy link
Collaborator Author

cderv commented Feb 19, 2025

Thanks for the additional information. Then post processing workaround seems to be the good solution here of OJS.

So

  • for OJS this is not possible and could be documented as limitation.
  • For algolia, we can probably add a configuration like with math.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request html Issues with HTML and related web technology (html/css/scss) ojs-engine Issues with the ojs engine search
Projects
None yet
Development

No branches or pull requests

2 participants