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

Make the plugin front-end load less kb size #259

Open
worldsdream opened this issue Oct 26, 2023 · 7 comments
Open

Make the plugin front-end load less kb size #259

worldsdream opened this issue Oct 26, 2023 · 7 comments

Comments

@worldsdream
Copy link

Hi Kevin,

I tried comparing the plugin with prismatic plugin. It uses the famous prismjs syntax highlighter.

See the screenshot for more information.

The "document" is bigger for Code Block Pro plugin compared with Prismatic plugin.
The Prismatic plugin loads 8 items with a total of 25,92 kb compared to Code Block Pro plugin loads 1 item with a total of 6,00 kb.

In my test:

Prismatic: 105,09 kb + 25,92 kb = 131,01 kb total
Code Block Pro: 145,08 kb + 6 kb = 151,08 kb total

comparison

Is it possible to make it smaller in size?

@KevinBatdorf
Copy link
Owner

It's a trade off of size for compute. Code Block Pro does very little compute on page load, and only does some font loading, line highlighting, and copy button event registration.

You could:

  1. disable the copy button (saves a copy of your code - so could be significant)
  2. don't use line highlighting or fonts
  3. then unload the JavaScript (saves the 6kb)

To unload the JS:

add_action('wp_enqueue_scripts', function () {
  wp_deregister_script('kevinbatdorf-code-block-pro-view-script');
}, PHP_INT_MAX);

@worldsdream
Copy link
Author

I don’t use line highlighting or fonts. Only the copy button. So I can’t unload the JS file.

I thought there could be optimization being made in the plugin so the “html” file will shrink.

@worldsdream
Copy link
Author

Can you tell me what would be better for core web vitals and speed? Is it better to have everything in the HTML file or separated files? So I can make a decision if I use your plugin.

@KevinBatdorf
Copy link
Owner

So the way other plugins work is they load in the JS library that does the parsing once the page loads, scans the page for code, then manipulates the document to add HTMl needed. Depending on the code and complexity of the tokens, processing them can be very slow in terms of web vital performance is concerned. Loading multiple JS files can be slow too.

At the same time, loading a larger single document can also be slow depending on your server infrastructure, compression, etc. These are easier to control with global caching, etc imo though.

It's a tradeoff though. I personally think that the less JS work being done the better. But on very slow connections, loading an extra 100kb document might be an issue too.

It also depends on the code you're typically writing too. Long code snippets with a lot of tokens will add more size then something less complex. For a lot of code the overhead might be only a few kb only.

The current trend is to pre-generate static pages and ship with little or no JavaScript, which is why I took this approach to begin with. I'm trying to leave out bias here, but of course I'd recommended using this plugin.

@worldsdream
Copy link
Author

Thanks for this explanation. I understand it completely now.

I am already using your plugin and it’s great. This is for a second site. So you know that I really like it a lot.

@KevinBatdorf
Copy link
Owner

Thanks and I appreciate the communication too. If you have any other questions or features or anything at all feel free to ask. Feedback is always helpful :)

@adriancs2
Copy link

adriancs2 commented Nov 20, 2023

Prismatic plugin analyze and generate coloring blocks at the client side browser, it consumes far more memory and cpu computation at client side per page. For Code Block Pro plugin, there is no code rendering required at client side browser, it's lightweight for the client's browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants