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
[Request] Provide a core version for CDN to be used in browser #3744
Comments
Yes, I was aware of the core module, but I meant a script that could be loaded in browser via <script type="module">
import hljs from "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/es/core.min.js";
</script> The module won't work: <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/es/core.min.js">
</script> I know that |
And of course you can build your own version easily enough with how every many (or few) languages you want... I think the version we currently ship is a great mix for many at a very low cost - only 40kb gzipped. I'm lost though. We currently ship core in both ESM (ES modules) and CJS (ILM) versions, I'm not sure exactly what you're asking for here. |
Sorry about the confusion. Yes, I know I can build my own version, and I was hoping for an "official" release. Let me try to clarify what I was asking for. First, this is what we typically do: <script src="build/highlight.min.js"></script>
<!-- then load extra languages we need, e.g., latex, which is not in :common -->
<script src="build/languages/latex.min.js"></script>
<script src="build/core.min.js"></script>
<!-- then load specific languages we need -->
<script src="build/languages/c.min.js"></script>
<script src="build/languages/latex.min.js"></script> I don't have much expertise on JavaScript, so please forgive my ignorance. If this core version is provided, I can use jsdelivr's Again, I don't know much about tools for building JavaScript, and my gut feeling is that this task could be done by adding a line after: highlight.js/tools/build_cdn.js Line 56 in 14aa378
something like this?
If that sounds about right, I can submit a pull request. Thanks! |
Yeah, this older usage (CJS/ILM) is what we're moving away from - in favor of ES6 everywhere. Simply use the new ES6 code (with modules) and you already have everything you need with existing builds. At the moment we have no plans to expand the scope of the CJS library. I may go away entirely with version 12 and those wanting to stay on CJS a bit longer would keep using version 11. |
Thanks for sharing the possible roadmap! I don't know your motivation to drop the support for CJS, but the old usage is critical to me. This made me take a look at Prism for the first time, although I've heard about it for a long time. I was happy to find out that it has exactly what I asked for in this issue: <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js"></script> And the core is tiny. I'll take a closer look in the next few days. I have been a happy highlight.js user for over a decade, and I truly appreciate the contribution from all authors/maintainers/contributors! |
Why?
Prism is great, but they are also going ES6 (and dropping support for older browsers) with the next release IIRC - though I'm not sure about their plans to continue to publish older CJS builds... |
Same old reasons: ongoing development and support costs are higher with multiple versions of things.
|
Just played around with this briefly, using
|
Maybe it's my ignorance, but to my knowledge, modules must be defined in external files. My use case is to make an html file self-contained (which can be easily shared and viewed offline) and not rely on external files, which means all JS code must be embedded in the html file. With the good old CJS, this is quite trivial to achieve---simply read the external JS code into the
Thanks! I was aware of tools like
I'm always in favor of dropping support for older browsers. I don't care about older browsers. If they are going to drop CJS builds, too, I guess the only way I could move forward is to build them by myself. I hope not to do that, but a last resort is better than none. |
This is an edge case already (yet readily solved with a tool such as
This is either a tip of the iceberg problem or else a "how high is too high"... We currently maintain (and test) 3 different builds of the project, we force 3rd party authors to worry about multiple build types. We must maintain documentation for require and import, etc... it's been quite painful trying to figure out the "best" way to ship a combined CJS + ES6 library... there are all sorts of small headaches that add up. This is all effort and complexity that we would rather not deal with - IF it can be avoided. Many libraries went ES6 only a year or so ago - we purposely held out then... but now it's time to take the leap. Those wanting CJS can easily use Highlight.js 11 a while longer, or just run us thru a build tool such a rollup to generate legacy output. |
Many thanks for the explanation! That makes sense (and also resonates with me as an open-source developer). |
Currently
highlight.min.js
is about 120Kb, which is not bad, but I often only need the support for only a few (most likely to be no more than three) languages on a page. I wonder if you'd consider providing a bare minimal core version on CDN, and users can selectively load the languages they need. This is possible for ES6 modules:and it will be nice to be able to do this in browser, too:
Thanks!
The text was updated successfully, but these errors were encountered: