Void
Void

Reputation: 189

How do you store large amount of text for a webpage

I have a book in docx format (about 25,000 words) and I want to display about 400 words at a time on my webpage. In Python, I have an algorithm that separates the text into pages and stores that in a dictionary; however, the frontend uses JavaScript.

I have tried to export the Python output as a txt/json file, but it seems that JavaScript doesn't allow automatic file uploading and instead requires the user to upload the documents which won't work for my situation. So, do I have to store all of the text (25,000 words) in an html document and then run a JavaScript version of the Python algorithm on that and then save it into local storage or some JavaScript container?

I want to avoid using a web host for this since I don't think it is necessary.

Upvotes: 1

Views: 1399

Answers (1)

Sanil Khurana
Sanil Khurana

Reputation: 1169

You would typically build a web API for retrieving data, you would use a database/flat file store for storing the data and the frontend would form the presentation part. Depending on your usecase and if you are not familiar with databases, I'd suggest as a first step you could just store the pages as simple files on the backend.

So, your data i.e. the pages of the book would be stored in text or JSON. Your backend service(which can be in Python or JS or pretty much any other popular language) would have APIs that facilitate retrieving these webpages and your frontend(HTML + CSS + JS) would be responsible for capturing user input and requesting data from the backend service.

So, the flow for reading a page becomes -

  1. The user opens the frontend, which would comprise of HTML + CSS + JS
  2. The frontend retrieves a page from the backend API
  3. The backend API reads the page on your machine and returns it

If the only reason you don't want to use a backend or host is because it is not required, in my opinion what you are trying to build would typically require a backend service since you'd generally want to have control of data so that you can have other mechanisms for auth, updates to the pages, etc.

Upvotes: 1

Related Questions