DEV Community

Cover image for TV Channel Website: Static Assets
Sokhavuth TIN
Sokhavuth TIN

Posted on

1 1

TV Channel Website: Static Assets

GitHub: https://github.com/Sokhavuth/TV-Channel
Vercel: https://khmerweb-tv-channel.vercel.app/

In Bottle.py, to be able to use static assets such as font, picture, JavaScript, and CSS files, we need to set a route to a folder to store those static files

The name of the static folder could be anything we like, however, people like to name it as "public" folder in the root directory. And the best place to set the route to this folder is in the entry point file "index.py". Moreover, in this folder, we can create as many sub-folders as we need to store different kind of files.

# index.py

from bottle import static_file, get
from routes.frontend import index


app = index.app

@app.get('/static/<filepath:path>')
def staticFile(filepath):
    return static_file(filepath, root="public")


###################################################################
import socket
host = socket.getfqdn()    
addr = socket.gethostbyname(host)
if(addr == '127.0.1.1'):
    app.run(host='localhost', port=8000, debug=True, reloader=True)

###################################################################
Enter fullscreen mode Exit fullscreen mode

After the route to static assets is set, we can use different kind of static files as below:

<!--views/base.tpl-->

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <title>TV Channel Website</title>
        <script src="/static/scripts/jquery.js"></script>
        <link href="/static/images/sitelogo.png" rel="icon" />
        <link href="/static/fonts/setup.css" rel="stylesheet" />
        <link href="/static/styles/base.css" rel="stylesheet" />
    </head>
    <body>
        Hello World!
    </body>
</html>
Enter fullscreen mode Exit fullscreen mode
/* public/styles/base.css*/

:root{
    --body-font: 14px/1.5 Vidaloka, OdorMeanChey;
    --background-dark: #541616;
    --background: #c64242;
    --background-light: #f7c2c2;
    --foreground: #fce4e4;
    --color: white;
}

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

a{
    text-decoration: none;
    color: #ff60ac;
}

a:hover{
    opacity: 0.7;
}

.region{
    max-width: 1100px;
    margin: 0 auto;
}

body{
    background: var(--background-light);
    font: var(--body-font);
    color: var(--color);
}
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay