observablehq / framework

A static site generator for data apps, dashboards, reports, and more. Observable Framework combines JavaScript on the front-end for interactive graphics with any language on the back-end for data analysis.
https://observablehq.com/framework/
ISC License
2.2k stars 89 forks source link

Should code be minimized #1502

Open mcmcclur opened 1 week ago

mcmcclur commented 1 week ago

I notice that comments, either in code or in markdown of a Framework project, are preserved in the output that appears in dist after build. Thus, if my index.md file looks like so:

# My lovely work project
This is an important project

<!-- Man, I cannot STAND my boss!!! -->

## Section 1

Then I might lose my job. :(

So, should comments be sanitized in a build?

Fil commented 1 week ago

You should definitely sanitize this comment if your boss can view source, but IMO it is not framework's business to do so. If you write a post-processor that strips comments, make sure to keep Framework's own comments, which are used as anchors for dynamic “cells” (e.g. <!--:55cc50bc:-->).

mcmcclur commented 1 week ago

Hi Fil, thanks!

I guess I was surprised to see the comments in production code for efficiency purposes, rather than for privacy. That is, it seems to be standard practice to not only clean comments but to also minimize and bundle production code to reduce transfer time and provide a snappier user experience.

I'm sorry if I wasn't clear on the motivation for the question.

Fil commented 1 week ago

Framework bundles and the css and js files coming from npm and node modules, but leaves the code blocks and HTML intact in the pages and js imports (edited). I can see how it could be useful to minimize those too on build. Maybe do not close this issue, but retitle it :)

mcmcclur commented 1 week ago

Framework bundles and minifies its css and js files, but leaves the code blocks and HTML intact

That does not seem to be the case. Certainly, the code that it links from jsDelivr is minimized but, as far as I can tell, Javascript files written by the app author are not. For example:

https://mcmcclur.observablehq.cloud/framework-for-math/_import/common_components/build_samples.11ccf515.js


I did reopen and retitle the project.

Fil commented 1 week ago

Ah you're right—currently only the npm/node modules are minified.