Reputation: 35
I have own Web server implementation based on C++ TCP sockets. Now this server can send plain text in HTTP body. I need this server to send static files (HTML, CSS, JS). Files are located in ./static/
directory (./static/admin.html
, ./static/admin.css
, ./static/admin.js
), server reads files contents and sends it to client with appropriate HTTP-headers. admin.html
file has link to admin.css
and admin.js
, like it shown in the code below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Page</title>
<link rel="stylesheet" type="text/css" href="admin.css">
</head>
<body>
<script src="admin.js"></script>
<!-- ... -->
</body>
</html>
1) How could client receive css
and js
files?
2) What is the common sense to serving static files?
2.1) Should I read *.html
file to buffer, inject to the buffer contents of *.css
in <style>
tag and contents of *.js
in <script>
tag? Is there another more effective/elegant/good way?
Upvotes: 1
Views: 2557
Reputation: 1
Modern browsers will did this for you, and all you need to do in server side is to response with correct files. Lol. Hope this will help you
Upvotes: 0
Reputation: 36401
Upvotes: 3