Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:24:08+00:00 2026-06-03T00:24:08+00:00

Imagine we have a server side application that generates streaming content full of JavaScript

  • 0

Imagine we have a server side application that generates streaming content full of JavaScript commands. The easiest way for me to show the example application is to use Python/Flask, however you can perform it using any language just flushing the output after each iteration. So, for a sample server side application:

from time import sleep from flask import Response

@app.route('/stream', methods=['POST']) def stream():
    def generate():
        for i in range(10):
            sleep(1)
            yield 'console.log("Iteration: %d");\n' % i
    return Response(generate(), mimetype='application/javascript')

which returns (during 10 seconds with 1 second pauses) this kind of output:

console.log("Iteration: 0");
console.log("Iteration: 1");
console.log("Iteration: 2");
...
console.log("Iteration: 9");

I need to create a “parent” HTML/JavaScript page which handles and executes these commands on-the-fly, i.e. not waiting until all 10 iterations will be loaded. Also, it should be able to serve POST requests to the mentioned server side application.

Here are the options which I have tried.

  1. I tested jQuery Ajax method with different options but it still
    needs full generated output to execute all commands at once.
  2. The other idea was to use iframe. It works fine but in order to
    use it I need to rephrase my output from console.log("Iteration:
    0");
    to <script language="JavaScript">console.log("Iteration:
    0");</script>
    with content type text/html; and also to simulate
    POST form submission to the target iframe.
  3. I have read about WebSockets. However, since this technology is not
    absolutely supported at the moment, and my application should be
    able to work with on-the-fly content already now, I refused to deal
    with it.

Another very important thing: the output should be a stream, since server side application works with a long lasting process; so make setTimeout(function() { $.ajax(...); }, 1000); is not the solution.

To summarize, I have tried several options but simple iframe is the only solution which really works at the moment. Otherwise, most probably I am missing something. Any thoughts and constructive ideas are very much appreciated.

Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:24:10+00:00Added an answer on June 3, 2026 at 12:24 am

    long-Polling and comet are options, but these are hacks. The Iframe method you mentioned isn’t terrible, but has some state issues if you need to recover the connection.

    I would encourage you to reconsider web sockets. There is a lovely shim available on github which uses flash (which has had socket support for some time now) as a fall back. You can write client side code as if web sockets exist, and the shim adds it to browsers that don’t support it. Great!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've implemented a server side application that records timestamps when records are created and
Imagine you have an entity that has some relations with other entities and you
Imagine you have a large dataset that may or may not be filtered by
I have to add e-mail notifications to a client server application. Notifications happen as
Imagine that you want to design a tennis booking system. You have 5 tennis
Imagine you have a large number of video files stored on a server, and
So imagine we have TCP server recieving all browser requests. How a cookie generated
I have server output that looks like this PLAYER_ENTERED name ipaddress username If the
I am writing a simple server (publisher) and client (subscriber) application to imagine inter-process
Imagine I have a table which stores a series of sparse vectors. A sparse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.