Skip to content
BoKSA

Publishing your application

Publishing your application

The front-end of your application can be published on the same website as your documentation, so anyone can open it from a link. This page shows where to put it and how to link to it.

It works because MkDocs only converts Markdown files. Every other file in docs/ (HTML, JavaScript, CSS, images, model files) is copied to the website unchanged.

Your application is public too

Everything a browser downloads can be read by anyone: your HTML, your JavaScript and every file next to it. Never put an API key in front-end code, and do not publish datasets that contain personal information. See What not to publish.

Where your application goes

Every application gets its own folder in docs/apps/:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
docs/
└── apps/
    ├── sign-language-explainer/
    │   ├── index.html
    │   ├── sketch.js
    │   ├── style.css
    │   └── model/
    └── gesture-game/
        ├── index.html
        └── main.js
  • The page that starts your application must be called index.html.
  • Name the folder after your application, in lowercase and without spaces. The name becomes part of the web address.
  • Agree on the folder names with your team, and only work in your own folder. That keeps you out of each other's way in Git.

After you push, the application is online at the address of your website followed by /apps/sign-language-explainer/.

Use relative paths inside your application

Your website may be published in a subfolder of a longer address. A path that starts with / points to the top of the server, not to your application, and will not be found.

1
2
3
4
5
6
<!-- Works everywhere -->
<link rel="stylesheet" href="./style.css">
<script src="./sketch.js"></script>

<!-- Works on your laptop, breaks online -->
<script src="/sketch.js"></script>

The same applies to everything you load from JavaScript, such as images, data files and models:

1
const model = await tf.loadLayersModel("./model/model.json");

Libraries from a CDN (an address starting with https://) are fine as they are.

In a Markdown page, link to the index.html of your application with a relative path:

docs/sign-language-explainer/index.md
1
[Open the application](../apps/sign-language-explainer/index.html)

.. means "one folder up". From docs/index.md, the same link is apps/sign-language-explainer/index.html.

To turn the link into a button, add { .md-button } directly after it:

1
[Open the application](../apps/sign-language-explainer/index.html){ .md-button }

Show your application inside a page

An <iframe> shows the application in the page itself, next to your explanation:

docs/sign-language-explainer/index.md
1
2
3
<iframe src="../apps/sign-language-explainer/index.html"
        width="100%" height="600" style="border: 1px solid #ccc;"
        allow="camera; microphone"></iframe>

Leave out allow="camera; microphone" if your application does not use them.

The path in an iframe is counted differently

MkDocs fixes the paths of Markdown links for you, but it does not touch HTML. On the website, a page such as iterations.md is served from its own folder, iterations/. So in an <iframe>, <img> or <script> tag you need one extra ../ on every page that is not called index.md:

Page Path in the iframe
docs/index.md apps/gesture-game/index.html
docs/gesture-game/index.md ../apps/gesture-game/index.html
docs/gesture-game/iterations.md ../../apps/gesture-game/index.html

If the frame shows a "404" page, the number of ../ is wrong.

Always add a normal link as well. An application in a small frame is hard to use on a phone.

Applications with a build step

If you use a framework or bundler such as Vite, React, Vue or Svelte, the browser cannot run your source code directly. You publish the built version.

  1. Keep your source code in a folder outside docs/, for example src-apps/gesture-game/.
  2. Make the build use relative paths. In Vite, that is one line:

    vite.config.js
    1
    2
    3
    export default {
        base: "./",
    };
    
  3. Build the application:

    1
    npm run build
    
  4. Copy the contents of the output folder (dist/ in Vite) to docs/apps/gesture-game/, so that docs/apps/gesture-game/index.html exists.

  5. Commit both the source and the copied build, and push.

Repeat steps 3 to 5 every time you want to update the published version. Add node_modules/ to your .gitignore; that folder must never be committed.

If your application uses client-side routing (addresses such as /about that only exist inside the application), use hash-based routing. Otherwise a visitor who refreshes the page gets a "404".

Small demos inside a page

For a small, single-file demo you can skip the separate folder and write the HTML and JavaScript straight into a Markdown file. The example page linear-regression-explorer.md in your repository works this way. Keep in mind that the styling of the website and of your demo will influence each other, so this only suits small things. For your actual application, use docs/apps/.

What cannot be published this way

The website only serves files. It cannot run a program.

  • No back-end. Python, Node.js servers and databases do not run on the website. Back-end code must run in a Docker configuration (for learning groups, see What you deliver). Commit it to the repository in a folder outside docs/, and explain in your documentation how to start it.
  • No localhost. A published front-end that calls http://localhost:8000 only works on a laptop where that back-end is running. For everyone else, show a clear message in your application, and add a screen recording to your documentation so people can still see how it works.
  • No secrets. If your application needs an API key, the call must go through a back-end that keeps the key. There is no safe way to hide a key in a front-end.
  • No huge files. Model and data files of a few megabytes are fine. Much larger files make the repository slow for your whole team. Prefer a smaller or quantised model, or load it from a public source.

Models that run in the browser, for example with TensorFlow.js, ml5.js, Transformers.js or ONNX Runtime Web, need no back-end at all and can be published completely.

Test before you push

Start the local preview and open http://localhost:8000/apps/gesture-game/. Open the developer tools of your browser (F12) and look at the Console and Network tabs. A red line with "404" means a file was not found, usually because of a path that starts with / or a difference between capital and lowercase letters. Model.json and model.json are the same file on Windows and macOS, but not on the website.

Camera and microphone only work on localhost and on addresses that start with https://.

Checklist

  • My application is in docs/apps/<app-name>/ and starts at index.html.
  • All paths in my application are relative.
  • My application works in the local preview, with no errors in the console.
  • My documentation page links to the application.
  • After the pipeline finished, I opened the published application in a private browser window and it works.
  • There are no API keys, passwords or personal data in my application.
  • My back-end, if I have one, is committed outside docs/, runs in Docker and is explained in my documentation.