Cache html page but not data - javascript

I have html_page.php that contains my html page,
javascript.js contains ajax to call process.php which lookup data from MySQL and populate into html_page.php.
Is it possible for me to cache the HTML structure of html_page.php but not the data in the fields?

It is hard to give you a proper answer without you giving us a context you are working on, but according to your question tags, I assume you are talking about using PHP.
You should refer to this thread on implementing caching on a PHP site.
Typically, you will need to use plugins and extensions that don't come out-of-the-box with PHP.
Some web servers also have caching functionality built into them, you should look up the documentation of your web server.

Related

Check if a certain string exists on a AngularJS web page by using php

I saw this answer Check if string exists in a web page - Check if string exists in a web page and it works
but what about checking for a string on an external web page that is using Angularjs? Is it still possible to search with php curl or another language should be used.
The simple answer is no, because the problem is that AngularJS is a clientside SPA framework. You would need to parse the JS and run it like a browser would, in order to determine the content of the page. I don't know of any PHP libs that do this.
The alternative without "just php" would be to use a web crawler. There are a couple out there that solve this exact problem. You could then technically use PHP to read the output of the webcrawler program. But then you might not need PHP at all...
If you're going to do any sort of serious page reading I would just use a web crawler/browser to do this. Why reinvent the wheel(browser) when you can just use it?

Can Googlebot crawl javascript generated content?

We have a web app that its content generated by javascript. Can google index those pages?
When we investigate this issue we always found solutions from old pages about using "#!" in links.
In our app the links are like this:
domain.com/paris
domain.com/london
When we use these kind of links, javascript populates content.
Is it wise to use HTML snapshot or do you have any other suggestions?
Short answer
Yes they can crawl JavaScript generated content, as long as you are using pushstates.
Detailed answer
It depends on your setup. Google and Bing CAN crawl javascript and AJAX based content if your are using pushstates. If you do they will handle content coming from AJAX calls, updates to page title or meta tags using javascript, and in general any such things.
Most frontend frameworks like Angular, Ember or Backbone already works with pushstates so in these cases you don't need to do anything. Check whatever system you are using to see how they do things. If you are not using pushstates you will need to implement it on your own or use the whole escapted_fragment html snapshot deal.
So if you use pushstate then yes, search engines can crawl your page just fine. If you don't then no, you will need to implement pushstates or do HTML snapshots.
Bonus info - Unfortunately Facebook does not handle pushstates, so the facebook crawler needs either non-dynamic og-tags or HTML snapshots.
"Generated by JavaScript" is ambiguous. That could mean that you are running a JS script on the server or it could mean that you are making an AJAX call with a JS API. The difference appears to matter as far as Googlebot is concerned. But you don't have to take my word for it, as there is empirical proof of what Googlebot will and won't currently cache as far as JavaScript content in the form of live experiments using both the XMLHTTPRequest API and the Fetch API. So, as you can see, server-side rendering is still going to be the best way to go for SEO.

How to save the html generated by javascript code so it can be sent by email?

I would like to convert a C# API I wrote, and that generates (static) html pages (mostly for rendering tables of data), into using angularjs. The goal is to better decouple the data and the html, allowing interactivity (for instance, sorting by a column) / re-use of the data, that go beyond what a static html page could ever offer.
Now the issue is that as soon as I use JS to generate part of my page, I cannot anymore send the html document as-is via email, because the JS will not execute from an email client. Yet, this is a useful feature of my API.
Is there a way around that?
I think I heard once a mention of a virtual browser (in node?), that could execute all the javascript (without GUI), and then dump the html into a file.
Otherwise, the only solution I could think of is to have C# generate the tables, hardcoding the values in the html (as is currently the case), and have angularjs still do all the json post-processing to allow the user to interact with the data. The annoying thing with that is that it will require duplicating some of the table construction logic in C# and JS, which is not great.
If you want to send email, then implement a service in Angular that calls some server side function to send the email. The data should be passed as some sort of view model. In ASP.NET, this server side function is often exposed via Web API or a generic handler (.ashx).
If you want the user to be able to download a file directly from the page, have a look at How to trigger a file download when clicking an html button or javascript.
It should be noted that directly using HTML intended for a webpage is often not a good idea to include in an email. The HTML parser in email clients vary widely, and you should likely use only a small subset of HTML features to ensure compatibility. HTML intended for a browser also often contain extra stuff (such as navigation menus) that isn't appropriate for an email.
Would using a Mailing API be something to consider? In that case you could just grab the contents and use angular to send it to e. g. Sendgrid.

Rails: How should dynamic content be loaded? Via some sort of templates?

I'm building a survey system where a user can pick various types of questions. Each question should be loaded into the current page.
There are 6 different question types, each with different settings/form fields. You can also add multiples of the same type of question.
So should I have the form templates stored and then load them dynamically (I'm using jQuery)?
And if so, where should they be stored and how should they be called (they'd have erb in them)?
EDIT: For clarification, I know how to do the javascript stuff. I'm curious from the Rails side of things how this works. Would I create a bunch of partials for each question type? And how would I load just the partial content?
I suggest: http://railscasts.com/episodes/197-nested-model-form-part-2
And in the link, comment 57 claims to have it unobstrusive way here: http://github.com/thb/surveysays
But I'd avoid using ajax for such kind of feature: if it can be done client side, do it client side :)
You can make an AJAX request to the server and have jQuery completely replace the content in a certain, say, <div> with new HTML content sent back from the server.
Take a look at the documentation for jQuery.load: http://api.jquery.com/load
From the Rails side, yes, have the forms in partials that are sent back via AJAX, but can also be included in 'normal' HTML requests for folks that do not have JavaScript enabled.

blogengine without php or asp.net etc

Is there a way to have a blog directly integrated into my HTML/javascript-only website, without having to have something like a SQL-database and a dynamic engine like PHP or MySQL?
Maybe there is some service in the web that offers this (hopefully without ads :) ). Or maybe I can have a blog engine entirely written in javasript?
Entirely written in JavaScript? Surely that defeats the entire point of having a "blog-engine" in the first place? The point being that the data is stored somewhere and dynamically retrieved. To avoid using anything server-side (which seems to be your intent), and only use HTML/JavaScript, you'd have to store all the data for the blog in files that are served up to each visitor, and then retrieve the data from the particular, local, locations using JavaScript.
Sorry if I'm misunderstanding the point here... but this seems to be an utterly useless way of trying to go about things. Blogs are, in general, either written statically (in HTML [even though this is rare]), or are dynamically generated from a database by a server-side scripting language (most common).
Edit: As an additional point, I suppose you could include some third-party blog feed, or service, in your page, via use of JavaScript... but I'm unsure as to which (if any) blogging services would directly support this method of working. Additionally, this is quite an unreliable way of including third-party data in a page...
Here's a thought. It's not really a blog engine - but a wiki.
Entirely javascript/html/css. All lives in a single html file:
http://www.tiddlywiki.com/
not sure how it would work on a real live site, but their site is using it:
* A personal notebook
* A GTD ("Getting Things Done") productivity tool
* A collaboration tool
* For building websites (this site is a TiddlyWiki file!)
* For rapid prototyping
* ...and much more!
You could use github pages. You will get a generated blog with version control.
Other option is to use a Desktop blog tool and then update your site.
You can user iWeb if you have a Mac or CityDesk on Windows or you may try this open source tool
Edit Today I came across this tool: Zeta producer that may help.
http://code.google.com/p/showdown-blog/
Blog engine written in just JS and XML [v0.6] {JavaScript, XML}
So, what you want is to have a blog where you're website provider doesn't provide a way to serve dynamic content?
The only way I see that you can do it in that case is writing html-files (or text-files if you prefer) and adding them to the site. After that you can have some JavaScript to add them to your "blog-page".
You of course need to upload them to the website in the same way as you do for the other files, and then have a way for the JavaScript to know which pages it should fetch.
I am not aware of any JavaScript blog-engines, but you can have a look at the templating functions in for instance Prototype
Of course, that means that you will have to fetch both the template and the content through Ajax and let the client do all the processing (could be slow and possibly insecure), and you still need to have a place to upload the content and update it.
Your best bet is going to be using a generator to create the HTML/CSS/JS to upload to your server, take a look at Webby: http://webby.rubyforge.org/
IF you really need to you can use a public api for a service that lets you post small bits of info and retrieve it using javascript.
for example if you only need small posts you can make a blog in html.javascript that utilizes twitter as the engine. of course you will be limited to 140 chars. I am sure there are other services that will allow a similar idea but with less restrictions.
And of course the best option - Get a blog software or host your blog with a service provider and link to it from you site.
Good luck
One solution would be to use some application that generates the static web pages of your blog, and uploads them to your web server. This way you'd have a blog with static content that could all be managed in javascript alongside your existing site, without needing to install database, daemon software, or additional dynamic web programming languages on your server. The static content generation could happen directly on your server if possible, or you could run the html generation tool locally and upload the output.
MoveableType has a tool like this. You still need somewhere to store the content of your blog, and for this MoveableType uses MySQL by default, so you'd still need to install a database somewhere, but the database could simply be one your local desktop.
MoveableType also has support via plugins or older versions that can retrieve data from a sqlite or other database. The advantage of sqlite is that it doesn't require installing daemons like MySQL does, you can just put a sqlite file on disk somewhere, give MoveableType the path to the file, and run the script to generate your static content.
There are likely other tools like MoveableType, and I have in the past generated blog-like web pages simply by writing small scripts to generate HTML. The main issue is just that you need somewhere for these scripts to fetch data from.
Another option might be to develop your blog using XSLT, ... with XSLT, you'd put the content of your pages in XML files, and then write a template in XSL that converts your XML to HTML.
If you google for 'static blog site generation' you might find other ideas/options, including Jekyll/github mentioned in one of the other responses.

Categories