Which programming language to pre-populate HTML div, based on date? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Which programming language would a designer/developer use in order to "pre-populate" events on a website based on the date the events would happen?
For example: suppose you have a restaurant, and each day you have a different "lunch special" or something. And on the homepage of the website, you've got a div that says "today's lunch special," followed by whatever the special that day is. Suppose you know what the special is going to be for the next 30 days, each day. January 1 - sandwiches. January 2nd - soup. January 3rd - pizza. and so on.
Would there be a way to put all of this information in ahead of time (presumably some kind of database), so that on January 2nd, the website automatically changes to "soup," on January 3rd, it changes to "pizza," etc etc? would it be possible to put the info in ahead of time, and have the site populate the info based on the date? or would you just have to go into the HTML every day, change it, then upload it to the server?
I'm assuming there is a way to do this, but I have no idea what kind of language one would use to do it. Maybe PHP for the data, then JavaScript to call on the data? I'm a bit of a newbie so any advice would be welcome.

There are three fundamental ways to do this:
On the server: In this situation, your server-side code (PHP, Perl, Java, C#, Python, JavaScript running on NodeJS/SilkJS/etc., or almost any other language) responds to the request for the page and builds the HTML on-the-fly; what gets sent to the browser is the complete, pre-filled page. A single HTTP request is made (for the main page; there will presumably be CSS and images and such).
On the client: In this situation, the page that is returned by the URL is static, but then it contains JavaScript code that makes a second request for the data from the server via another URL. Server-side code on that URL runs, returns the data to the client (typically as JSON or XML), and the client-side JavaScript code interprets that data and fills in the page. Note that there's still server-side code involved, but the code actually filling in the page is on the client. Since it's on the client (browser), this'll be JavaScript. At least two HTTP requests are made (one for the main page, one for the data).
On the client, take 2: The main URL is handled by server-side code, but the server-side code returns static HTML (as in #2) but with the data the client would request in #2 embedded in the page. Client-side code reads the embedded data and fills in the page. Again that code would be JavaScript. A single HTTP request is made (other than CSS and such).
#2 seems a bit silly — why make two HTTP requests? — but isn't uncommon for sites with large, complex HTML pages: They serve those large static pages from a CDN (Content Delivery Network, a high-speed, usually static-pages-only way to get data to end users) and allow them to be cached, and the dynamic data from a server that just responds to data requests and doesn't allow caching those responses.
#3 is for the case where you may request updates to the data while viewing the page. So you want the client-side code to have the logic for populating the page, but you want to minimize HTTP requests when the user arrives to start with. So you pre-bake the first set of data into the page, but then periodically request updates, which is why you use client-side code to populate the page.
Above I've said that the client-side code would have to be JavaScript. It has to be JavaScript by the time it reaches the browser, but there are now several languages that "compile" to JavaScript, such as TypeScript, CoffeeScript, and Dart. So if you liked, you could write your code in one of those languages and "compile" it to JavaScript to send to the browser.

Related

Question ... I am studying the $ .post () method, however, I only see examples with PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Good night guys!
I'm new to programming and now I'm studying the $ .post () method and I have a few questions:
1 ° - Why should I use the $ .post () method?
2 ° - In all the examples I see, they always use the $ .post () method to send something to PHP ... Is it possible to send something other than PHP? If so, could you give me examples using only JQUERY, HTML, mysql and JSON? (that I'm studying)
Note: I'm a beginner.
$.post() is a jQuery method that allows you to send a request to a server (typically) with data that can be processed by the server and sent back.
PHP is a programming language that can run in a server, accept the $.post() request, and process the request.
$.post(), the jQuery method, is used in the "front-end" of web apps. The front-end is the part the user uses. So, a typical example of the use of a $.post() request would be a user on a social media app adding new images to their profile. The image is transformed into data (bytes) and sent from the users computer to the server with the $.post() method.
That's where PHP comes in. PHP will receive the data bytes and save it to the users profile. All the magic of making sure we have the right user and pulling up their info then adding the new image to their profile actually happens here. At the end of it, typically a "success" or "error" response is sent. For reference, when you get a 404 error or a 500 error, that is where the error came from. A server.
The front-end of web applications is very limited. It only has JavaScript, jQuery (which is just a sub-set of JavaScript), HTML5, CSS3, and some altered versions of these.
The back end, the server that handles all the requests and sends all the data back, can be done in a plethora of different languages. PHP is an older language but it is still actively updated and still used in a lot of legacy apps. We now have Node.js, Java, Python, etc. A lot of different languages to write a back end.
Hopefully this clears some things up for you. Please feel free to ask me questions in the comment section or send me a message if you don't have enough reputation to comment yet (don't know the numbers lol).

Python CGI With Data Return [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to accomplish the following:
Pull information from a module through Python. [Accomplished]
Constantly pull information from Python for use in HTML.
Avoid writing the entire HTML/CSS/JS document in print statements.
I've seen the term CGI thrown around, but don't really understand how it works. Simply put, I want to run the Python script which returns an integer value. I then would like to take that integer value into JavaScript so that it may update the designated tag. It should be able to execute the Python script every two seconds, receive the output, then apply it to the page. I do not want to write out the entire HTML document in Python by doing one line at a time, as I've seen some people doing on sites I've found.
It seems like doing something like this is far more complicated than it should be. The page should run, call the script for its output, then give me the output to use.
Well if you don't know what CGI is and find that what you ask for is "far more complicated than it should be", you first have to learn the HTTP protocol, obviously, and that's way to broad for a SO answer.
Basically what you want requires:
an html document
some javascript code, either linked from the document or embedded into it
a web server to serve the document (and the javascript)
a web server (can of course be the same as the previous one) that knows how to invoke your python script and return the result as an HTTP response (you'll probably want a json content type) - this can be done with plain CGI or with a wsgi or fcgi connector, in your case CGI might well be enough.
Then in the browser your javascript code will have to issue a GET request (ajax) every x seconds to the web server hosting the Python script and update the DOM accordingly.
This is all ordinary web programming, and as I said, a basic understanding of the HTTP protocol is the starting point.
Trying to write anything from scratch, if you don't know anything about the subject, is always going to be complicated.
That is why there is a whole world of tools to help you. I don't think you want CGI at all; look into one of the Python micro frameworks, in particular Flask. The tutorial there should give you the introduction you need.

How should I make a poll for my website? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to make a poll for my website.The poll I want should look like the poll on http://www.premierleague.com/en-gb.html.I am not sure if I should use PHP,Javascript or etc to make a poll.Can anyone help me in this? Thanks...
You're going to need to create a form and receive the data on the server side using PHP. Then you're going to put that information into a database.
I hope I do not come across as too mean but, the decision on which language to use is pretty simple when compared to actually coding it. I'm betting you are not entirely experienced with web-based programming languages. I would strongly suggest you look for some pre-made scripts in the interim:
Here is a simple tutorial on creating polls: http://code.tutsplus.com/articles/creating-a-web-poll-with-php--net-14257
If you are OK with the idea of using a CMS, Here is a WordPress Plugin that should do the trick: http://code.tutsplus.com/articles/creating-a-web-poll-with-php--net-14257
Otherwise, it's important to understand the flow of data:
Display the poll to the end user (use HTML forms and CSS to style)
Client submits data (either built in submit functionality or Ajax)
Server Receives data and stores it into database (php)
Page is re-loaded and results are displayed (read with php, then displayed using html/css)
In other words, you are going to use many of the available languages and tools to create a polling script.
Start with a pre-built one and look up other resources to learn to make/customize your own.
If you need to save poll values, than PHP/MySql + JS for live effects, animations + CSS for styling.
Create database tables.
Create HTML form.
Style form to fit your needs (maybe jQuery UI).
Use Ajax to submit form.
Use PHP to gather information form user, validate it and save to database.
Reload user poll view to see changes.
Sell this masterpiece to Google/MS/Apple (or any other company).
Take big cup of hot chocolate.
Rule rest of the world.
Good luck.
Yes, you can use PHP or any server side scripting for validating, storing, processing poll, and use HTML/CSS/JS for client side, this is the main whole web page. You should also have DBMS (Database Management System) like mySQL, msSQL, etc., for storing poll answers.

Difference between clientside and serverside (ajax) rendering for search page, concerning SEO [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I'm working on a page that is more or less a search tool, it basically consists of an input field, and it will show a list of entries to the user, according to the input. In this situation, if there any difference for SEO if the page uses client or server-side rendering (using AJAX) and why?
I'm just concerned if it's a disadvantage if I use client-side rendering in this particular scenario.
I understand that client-side rendering is a disadvantage for SEO compared to server-side - when the HTML is complete at the beginning, so to say. But in a dynamic case, where the results have to be loaded asynchronously anyways, is it still a disadvantage? Does it depend if the current content can be mapped to a URL?
AJAX loading of content has no impact on SEO.
The updating of the DOM via JavaScript will not result in any noticeable changes in what is indexed by a search bot. Almost all legitimate search engines archive the non-dynamic version of a webpage.
In order to enable SEO you have to maintain embedded links to non-dynamic versions of that content.
For example (using jQuery):
<div class="next-page"><a class="ajax-me" href="/page-2.html">Page 2</a></div>
$(document).ready(function(){
$(".ajax-me").click(function(e){
e.preventDefaults();
$('#ajax-target').load($(this).attr("href"));
});
});
That will enable AJAX for links, but still make that link visible to the web crawler for search engines.
Your server will have to know to respond with either a full webpage or AJAX response based upon the header request.
Since you don't seem to be much concerned with UI/UX and want to know more about SEO, I'd suggest to go with the client side. Anything that's dynamically loaded after user's input won't be visible to web crawlers.
However, another approach would be to make it work both ways - so that by visiting a specific URL (site.com/search?q=something) you get the page fully rendered from the server side, while you're still able to make another search that will happen at the client side. You'd still have a little trouble indexing all the relevant searches, but perhaps you could track the last x searches and show them somewhere on the page, with links to full server-side rendered search pages, like the one I mentioned above. You can even make those dynamic calls not only change the content of the page, but the URL hash in the browser's address bar as well (see here).
That way you'd provide users with a nice user interface/experience, while still doing a very nice SEO job since the crawlers would be able to index the links from the list of last searches.
So, to directly answer your question: client-side vs. server-side page rendering - huge SEO difference

What are the use-cases for Web Workers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am looking for real-world scenarious for using Web Workers API.
John Resig (of jQuery fame) has a bunch of interesting examples of using web workers here - games, graphics, crypto.
Another use is Web I/O - in other words, polling URLs in background. That way you don't block the UI waiting for polling results.
Another practical use: in Bespin, they’re using Web Workers to do the syntax highlighting, which you wouldn’t want to block your code editing whilst you’re using the app.
From Mozilla: One way workers are useful is to allow your code to perform processor-intensive calculations without blocking the user interface thread.
As a practical example, think of an app which has a large table of #s (this is real world, BTW - taken from an app I programmed ~2 years ago). You can change one # in a table via input field and a bunch of other numbers in different columns get re-computed in a fairly intensive process.
The old workflow was: Change the #. Go get coffee while JavaScript crunches through changes to other numbers and the web page is unresponsive for 3 minutes - after I optimized it to hell and back. Get Back with coffee. Change a second #. Repeat many times. Click SAVE button.
The new workflow with the workers could be: Change the #. Get a status message that something is being recomputed but you can change other #s. Change more #s. When done changing, wait till status changes to "all calculations complete, you can now review the final #s and save".
I have used them for sending larger amounts of data from the browser to server. Obviously, you can do this with regular AJAX calls, but if this takes up one of the precious connections per hostname. Also, if the user does a page transition during this process (e.g clicks a link), your JavaScript objects from the previous page go away and you can't process callbacks. When a web worker is used, this activity happens out of band, so you have a better guarantee that it will complete.
Another Use case:
Compressing/De-compressing files in the background, if you have a lot of images and other media files that are exchanged from the server in compressed format.

Categories

Resources