In my company we have a web-based tool that you enter an account, press a button, and the page takes a little bit to load, then loads account information. There are several different pages that do the same thing but load different information. I have already been able to make the sites load with direct URL execution (with an intermediate page and some JavaScript) so I only have to enter their account number once. My problem is, I want them to pull up all at the same time to speed things up, but there is some kind of lock that does not let you run the lookup in two pages at once. I want to make my site load the first page, then wait til it loads and immediately begin loading the next page in another tab on my page. Is that even possible in HTML and JavaScript? If so how, if not, what other language do I need to learn today?
check out the jquery's $(document).ready();
simply use
$(document).ready(function () {
//execute script that calls another page, you could use ajax
});
other method is using iframes, which i personally don't recommend
Do you mean something like Pageflakes?
If so, you will need to utilise AJAX (and/or webservices). A good tutorial/source code on building something like this is at DropThings (which is from the same author as PageFlakes).
This is using ASP.NET C# and AJAX Control Toolkit.
If the two URLs are loaded into separate <iframe> elements then you just need to create a load event handler for the first frame to set the src attribute of the second frame.
Related
This might just be because I'm not entirely sure how to word it properly, but here's an overview of the problem.
I have a site where it pulls the main content using ajax, and by using pushState, I change the url. Say from "site.com/" to "site.com/area". But reloading this page (or entering it in the url) causes it to completely fail (because there's no such thing as site.com/area).
Is there a way to load the page from that link?
Note, that this isn't about the history / back and forward buttons. I simply want it to load a page from that kind of link.
The page must exist in one way or another. Depending on what server you're running it on you can redirect all requests to your first page if you want to solve it like that. Then you don't have to create a new page for all "routes", but can build it into your first page/application.
But the page must exist in one way or another.
We have a news website where we cache a complete article page.
There are 4 areas that need to continue to be dynamic on that page:
View Counter: We add +1 to view_counts of that article when page loads.
Header: On the header of the website we check if session->id exists or not if it does we display a Welcome [Name], My Profile / Logout and if not we show Register / Login.
Comments: We display the comments made for that article.
Track User Behavior: We track every single action made by users on the site
Now the only way we could think of doing this is through AJAX calls:
$('#usercheck').load(<?php echo "'" . base_url() . "ajax/check_header'"; ?>);
And so on.
This is creating a massive load on CPU, but what would be the right/alternative way of approaching this?
Please see attached:
First of all, you do not have to use AJAX for every possible dynamic content, especially in the case of comments, you may as well load them via an iframe.
That way, you are not relying on Javascript to make the request.
It may even work for the counter.
However, you problem is not Javascript, nor the database server, based on what I can see from your graph. It seems to me you have some heavy PHP controllers, maybe you are loading a heavy framework just to have $session->id checked.
Further, what do you mean by "we track every single action"? How do you track them? Are you sending an AJAX request from every little thing or are you debouncing them with JS and only sending them one every 30 seconds or so?
My advice is that you consider the size of the PHP code you are calling, and slim it down as much as you can, even to zero if it seems feasible (by leveraging localStorage to keep track of you user session after the first login), and maybe loading the counter and the comments in alternative ways.
For example, I infer you are only checking the counter once per page load, ignoring subsequent loads by other users while the current user is reading the article, so your counter may happen to be out-of-date once i a while, depending on your traffic.
I going to explain it better: your page has n views, so when I load it, you request for n and then display n+1 to me. While I'm reading, the same page gets requested and viewed x times by other users. Your counter on the server has been surely updated to n+x, but the counter on my page still says "n views".
So, what's the point in being picky and showing n+1 to me and the not updating it, thus being off by x?
So, first of all the counter controller should be as slim as possible, and what if you loaded it within an iframe, auto updating without AJAX?
How to refresh an iframe not using javascript?
That would keep the counter up-to-date, you may render it with PHP just once per page view, and then just statically serve the resulting HTML file.
Hello I have a question recently I seen more and more sites using #/pagename instead of going to /pagename which is useful because it does not reload the page.
How can I do the same thing with jQuery? http://mysite.com/id#/1 <-- would load user with id 1 if you would change that 1 to say 4564 http://mysite.com/id#/4564 the page would load user data fro 4564 with out refreshing the page it self.
Thanks in advance
You are actually seeing two things:
The request for content is be done asynchronously (AJAX). To accomplish this look at jQuery.Ajax. http://api.jquery.com/jQuery.ajax/
There is also a 'hash trick' to enable back button support. Typically, a standard Ajax call does not play well with the back button. For this look into the BBQ jQuery library. http://benalman.com/projects/jquery-bbq-plugin/
Hope this helps.
Bob
YOU are looking for the jQuery history plugin. I've had great success with it, and there are triggers for when the hash changes so you can do whatever you want: load content with AJAX, or load a different slide, etc.
I would recommend you look at sammy.
It's a very light javascript framework intended to implement a thin-server model like this where the rendering occurs on the client's computer in javascript instead of served pages from a remote server. This is what allows many sites to avoid doing full reloads of a page every time a user performs an action.
Some operations are time costly and it takes long time while waiting them to finish.
Sometimes timeout occurs.
I want to use a real time progress bar, so I want to show the status to the user and also I want to prevent timeout. Which technologies must I use? JS, Ajax, multithread or both? and how can I iplement this?
Please advice.
I'd recommend using a library like jquery.
Here are some links:
jquery progress bar link 1
jquery progress bar link 2
Enjoy.
The easiest thing I can think of would be to implement a progress variable linked to the session (or a unique id) which is updated every so often by the slow-loading script. You can then have a 2nd page which returns the current contents of this variable. Query the status variable via ajax every few seconds to update your progress bar.
Alternatively, you can use this method without ajax. Basically you flush a script that displays a progress bar to the browser from the slow page. As the page continues loading, it flushes javascript update() calls every so often to update the bar.
http://devirtu.com/2008/10/16/making-progress-bar-of-page-loading/
If you are using an javascript and ajax, you can call / initiate the process(in server) from java script using an ajax call.You can show the user a loading image till you get a response back from the server. www.ajaxload.info allows you to generate your own loading images. have a look # it.
if you use jquery ,things would be much easier.
Check these links
http://docs.jquery.com/Ajax/load
http://www.shawngo.com/gafyd/index.html
Cheers
I have been reading Yahoo's Best Practices For Speeding Up Your Website, but still have a question that I could really use your help with:
The very first page of my web app needs to display a bunch of data that is dependent on the city the user is in. On the first visit, the user is prompted to pick her city and I store a cookie in the browser recording which city to start with. On her following visits to the site, the Javascript code checks the cookie and retrieves the data for that city as JSON.
Given that this data is necessary to display the fundamental part of the page, where should I load it from? Currently I am doing it from the top of Jquery's $(document).ready(), but it occurred to me that by definition that only gets executed once the entire page has loaded.
Which is the correct way to do this? (Eg, will it improve matters if I instead put some Javascript in the that checks for the cookie and loads the JSON feed for the right city? Some other solution...?)
Thank you for any insight
lara
Currently I am doing it from the top
of Jquery's $(document).ready(), but
it occurred to me that by definition
that only gets executed once the
entire page has loaded.
$(document).ready() will be called when the DOM is ready for manipulation, not when the entire page has loaded. The DOM will be ready as soon as the markup has been read and parsed into the DOM. This occurs before the entire page has loaded.
Putting your code to check the cookie value and retrieve city-specified data in $(document).ready() is perfectly fine.
If you really need this data to show the page correctly, how about simply inlining the data in the page itself? Save yourself an AJAX round-trip, be nice to your users in sub-Saharan Africa on the 300 baud modem.
I think the $(document).ready() is as soon as you can do it, although I'm not sure why you wouldn't just inspect the cookie values on the first request. Just check to see if they are set, and if they are, get the content for the user there are save yourself having to make any AJAX call. Maybe I'm missing something in your situation, but cookies are always sent with every request to a specific domain so AJAX/JavaScript shouldn't be necessary.