[>_]in/$cat /posts/prismjs-loader.md
~/posts/prismjs-loader.md

PrismJS Loader

2025-03-29 · 356 words · 2 min read#prismjs#syntax highlight

Discover Prism.js Loader, and learn how it quickly integrate your webpages with PrismJS-Coding syntax highlight

Hey there! Are you looking for a quick way to highlight coding syntax on your website? Check out Prism.js Loader. Simply grab the script and place it at the end of your web page, then you're all set! If you're curious about how the script works, keep reading.

Official Integration Method for PrismJS

Follow these steps to integrate PrismJS officially:

2.Choose the languages you want to highlight on your website.
3.Select the plugins you’d like to include.
4.Pick a theme that suits your site.

After downloading, you’ll receive a JavaScript file and a CSS file. Add them to your site, and you’re done!

PrismJS Loader: A Smarter Alternative

PrismJS Loader

One limitation of the official integration is that it bundles all selected languages and plugins into a single JavaScript file, which can slow down page loading. If your webpage only needs to highlight one language, you might still end up loading unnecessary resources.

To solve this problem, PrismJS offers a plugin called Autoloader to only load language package needed for your sites. Building on this idea, I created PrismJS Loader to make the integration process even more easier.

Features of PrismJS Loader

When the PrismJS Loader script runs on your webpage, it will:

1.Download the theme file (CSS) based on user parameters or use the default theme if no parameters are set.
2.Fetch the Prism core file and the Autoloader plugin.
3.Wait for all scripts to load and then apply coding syntax highlighting.
4.Use the Autoloader plugin to dynamically determine and load only the language packages needed for your webpage.

Benefits

-PrismJS Loader executes after your webpage has loaded, so it doesn’t impact page performance.
-The script automatically download themes based on the browser’s preferred mode (light or dark) and defaults to the specified theme if no parameter is provided.
-All Prism files are fetched directly from jsDelivr, ensuring reliability.

Conclusion

PrismJS Loader is the ideal solution for developers who need a quick and efficient way to integrate PrismJS without compromising performance. Check it out!

[>_] in $

type a command and press enter, or press ⌘K for suggestions

Run a command

Help

how this site works · esc to close

About this site

This is Trinh Nguyen's dev blog, dressed up as a terminal. Instead of clicking through pages, you run commands against a small virtual file system with three directories:

~/posts~/topics~/about

How to use it

  • Type a command at the prompt and press enter. Output is added below, like a shell session.
  • Press ⌘K (Ctrl+K on Windows/Linux) to open the command palette with suggestions and your recent commands.
  • The /posts, /topics and /about links in the header are shortcuts for cd ~/posts && ls and friends.
  • Chain commands with &&, e.g. cd ~/about && cat me.md.
  • To read an article, ls a directory, then cat the file you want.

Commands