Author Topic: Weird situation  (Read 3825 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Weird situation
« on: September 09, 2013, 08:49:00 PM »
So I have a client with multiple websites/applications that I built.  He builds these displays using one of the tools I made that outputs these sets of tables of data.  But he wants to embed these tables in several of his websites.  So what I'm currently doing is just generating the data using a public page and wherever he wants to include it, he just does:

Code: [Select]
<?php echo get_file_contents("http://www.site.com/blah/abc.php?param1=a&param2=b"); ?>

This works fine and it's very simple for him to embed things.  The problem is that this is obviously called before the page loads and some of these tables are very time intensive to build.  So I'm wondering if there is a way to retain the same functionality but also ensure that these don't hold up the loading of the rest of the page.

I was thinking I could just have the get_file_contents return a container with some jQuery AJAX action to pull the data, but I still need a way to stop that from working until the calling page is loaded.

Any ideas?

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Weird situation
« Reply #1 on: September 09, 2013, 10:27:06 PM »
OK, so I did what I figured would work.  Now the remote call to grab the contents of that page just downloads a div with an AJAX call that waits until all objects including images are loading and then it pops in the content.

If anyone has a better way to do this, I'm all ears.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Weird situation
« Reply #2 on: September 09, 2013, 11:25:20 PM »
I think AJAX is the way to go, especially since you already built it, but if you're concerned about it working without javascript, then I'd suggest a simple iframe.  The parent page and frame would load separately.

Is it fairly regular data that you can cache after the first load?
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

KnuckleBuckett

  • Jackass In Charge
  • Posts: 8674
  • Karma: +26/-259
  • [url=http://google.com]I search a lot[/url]
Re: Weird situation
« Reply #3 on: September 10, 2013, 06:03:55 AM »
I think AJAX is the way to go, especially since you already built it, but if you're concerned about it working without javascript, then I'd suggest a simple iframe.  The parent page and frame would load separately.

Is it fairly regular data that you can cache after the first load?

Bullshit.  Softscrub all the way.  Bloody amateur.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Weird situation
« Reply #4 on: September 10, 2013, 08:06:08 AM »
Comet FTW!
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Weird situation
« Reply #5 on: September 10, 2013, 10:53:29 AM »
Div replacement should work fine. If you wanted more flexibility (and more client side coding) then have the "API" return JSON instead of a div and then have the client page build whatever structure is needed, which would probably be considered the "better" way. I actually sort of prefer the div replacement method if you have control over everything (like layout), but Javascript folks would probably give you crap for that.
This signature intentionally left blank.

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Re: Weird situation
« Reply #6 on: September 10, 2013, 11:12:43 AM »
Ober,

just curious as to why you're waiting for the images to load before you call in the remote content? From your description it seems like you could make that call once the  containing div is loaded into the DOM.


micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Weird situation
« Reply #7 on: September 10, 2013, 11:18:53 AM »
Div replacement should work fine. If you wanted more flexibility (and more client side coding) then have the "API" return JSON instead of a div and then have the client page build whatever structure is needed, which would probably be considered the "better" way. I actually sort of prefer the div replacement method if you have control over everything (like layout), but Javascript folks would probably give you crap for that.

I've been wondering about the best practice on this recently. I previously always swapped out HTML but recently have started using javascript to draw the HTML from a JSON object, like you mention.  for example, this page: http://riverfront.org/about-us/news

I've never been a "javascript guy" but I see great value in separating the code that generates the data from the code that outputs the interface.
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Weird situation
« Reply #8 on: September 10, 2013, 11:50:14 AM »
micah, that's true if you're treating it like an API, which is a good idea for reusing between apps. If it's within the same app, you could probably be using templates or taglibs (or whatever their called in your framework) and that can be the reusable component. JSON is generally preferred but like I said it can lead to more code and that I don't always agree with if it's not for good reason. And you also need to consider complexity of rendering since the server side can usually render faster and cache which can be an important performance decision. Too much javascript on the client side isn't a good thing at the moment IMHO.

I've been talking with a few people lately about working on a framework that only outputs JSON but haven't really cared too much since that's more of a discipline thing that a requirement. Would make for an interesting technology stack though and help clean up a lot of code by forcing you to think more in APIs than presentation.
This signature intentionally left blank.