Using custom type attribute in <script> tags such as jQuery's text/x-jquery-tmpl - jquery-templates

I noticed that jquery's beta template plugin is using, the type attribute "text/x-jquery-tmpl"
e.g
<script type="text/x-jquery-tmpl">
I've not seen custom use of the type attribute in the past. Has anyone seen current examples of this in use or perhaps ways mere mortal developers such as I can use this in our own code?
I presume that it's sort of a MIME type, however I would of thought that MIME type support was up to the browser. So I would of assumed that custom MIME types would be unsupported?

The type actually does indicate what sort of script is there. If the browser doesn't understand it, it should ignore it. In this case, it's a convenient and semantic sort of way to include the source of the template without displaying it on the screen.
Usually with jquery template, you'll give it an id and refer to it that way with your $(id).tmpl call.
script def here:
http://www.w3.org/TR/html401/interact/scripts.html#idx-scripting_language
examples of tmpl here:
http://api.jquery.com/tmpl/

No, MIME are provided by the server to identify resources. The browser then acts on the types it recognizes.
Yes, in the HTTP connection the browser lists the types it can recognize so the server can choose types that fit better (an example here would be HTML 5 and video, where you have some codec options and the browser may support only a subset).
In this case, the specific MIME helps to signal the browser a warning: "This is not normal Javascript, don't act on it like if it was."

Related

AEM/Sling: How do I implement dynamic sling selector?

TLDR: I want setup an AEM page that accepts firstname and lastname as parameter using an SEO friendly URL.
Going to www.host.com/mycontent.richard.williams.html will display information relevant to Richard Williams.
If I go to www.host.com/mycontent.john.smith.html, the page will display information relevant to John Smith.
SEO friendly example: www.host.com/mycontent.richard.williams.html
not SEO friendly example: www.host.com/mycontent.html?firstname=richard&lastname=williams
So I've been following this guide (not sure if this is the best example/guide to help me): http://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/
And while it works well for my the example
#SlingServlet(resourceTypes="geometrixx/components/hompepage", selectors={"firstname","lastname"}, extensions="html",methods="GET", metatype=true)
I am trying to make it dynamic.
At the moment, I can only access the servlet if access via: http://localhost:4502/content/geometrixx/en.firstname.lastname.html
I want to make firstname and lastname dynamic parameters/selectors. Like if for example I want to pass the values "richard.williams", I can then use: http://localhost:4502/content/geometrixx/en.richard.williams.html
if I try to use http://localhost:4502/content/geometrixx/en.richard.williams.html right now, I get a blank page.
So basically I want to use selectors for passing parameter values to my page.
Any ideas how this can be done?
ps. At the moment, I only testing/experimenting in my local instance of AEM.
Selectors in sling don't provide the functionality of placing variables in the URL path. i.e. you cannot add {pathParam} like in Spring to sling servlet URL.
In general, selectors are not recommended to be used like an input to a function. They are to be used more like file extensions.
For eg. A request to /mycontent.html returns the same resource as /mycontent.mobile.html. The only difference being, the latter requests for a mobile friendly version.
Request params on the other hand serve the purpose of providing inputs to the servlet.
I cannot think of any direct way to attach a servlet to dynamic paths in sling. You can try using suffix, they are cacheable in the dispatcher, but I can't comment on the SEO friendliness of using suffix.
Consider this URI - /mycontent/user.json/john/smith
Register a servlet using the path /mycontent/user and you can use
String[] names = request.getRequestPathInfo().getSuffix().split(suffix, '/')
to retrieve the suffix contents.
Take a look at answers in this question. Sling ResourceProvider and integrating with jax-rs are other ways you can accomplish this.
Technically this would be feasible with the use of OptingServlet (see https://sling.apache.org/documentation/the-sling-engine/servlets.html#optingservlet-interface)
Your accepts method could easily recognise the expected resourceType and react appropriately.
As mentioned in the docs this approach is discouraged and the solution proposed by Subhash to use suffixes seems way more elegant.
You can create a components which reads selector from the request and add that compoent to en.html

What kind of code is http://ogp.me/ns/fb#

I'm not asking what it does, in the sense of, "It makes your Facebook Like button work."
What I am asking is, is this javascript, is it css, or what? It looks like a class. If I wanted to write my own similar file, what extension would I use to name it?
The reason I am asking is I would like to make my own class, for my own widgets, and reference my own class by putting something like xmlns:zz="http://mydomain.com/mylibrary/zz#"
It is JSON, as the name implies is a subset of JavaScript, but as it is designed for encoding data not code it can actually be parsed by most programming languages.
The extension don't matter but could be .js as it is commonly served with the MIME type text/javascript.
The is no way of using it with XML namespaces as you are hoping.
That URL redirects to http://graph.facebook.com/schema/og/#, which returns JSON.

dealing with itextsharp XMLWorkerHelper.ParseXHTML strict behavior

While trying to use XMLWorkerHelper.GetInstance().ParseXHTML() i find that it is really strict. Any wrong order of tags or unclosed tags will cause it to throw exception.
I am converting HTML that I have no control over.
Are there any flags to make it less strict? An input callback interface to handle funny markup? Anything in the itextsharp.tools.xml.html? Or an entirely new library compatible with itextsharp.text.IElement?
The name of the class and that method pretty much sums it up - you can't. The entire pipeline is based on the assumption that a valid XML document will be passed in, everything else will throw an exception. You can customize the pipeline and add your own handlers for things like link resolution, custom CSS properties and new HTML tags, but the core document processor still needs valid HTML.
I would recommend looking into running your HTML through a library that can convert it to XHTML.
EDIT
Also check out wkhtmltopdf. It uses webkit to render HTML and does (apparently) a pretty good job.
How to use wkhtmltopdf.exe in ASP.net
wkhtmltopdf.exe System.Security.SecurityException on cloud web server. How can i override server security policy
C# html to pdf converter using wkhtmltopdf or any other free tools

How to load html head tags from one source

Okay, for static pages. Is there a way to load everything between the head tags (css,javascript,etc) from one source so we don't have to load it in every html file? I know this may be a stupid question but I couldn't find one on here and if there was already a post about it, I guess I was stupid to miss it.
If you environment permits you can use Server Side Includes http://httpd.apache.org/docs/current/howto/ssi.html which doesnt really involve using traditional dynamic scripting languages or servlet technology. In any case the HTML standard also allows you reference external CSS and JS - they dont have to be inline. If they are at the same URL they will only get loaded once by the browser.

Node/Express/Mongo: How do I render HTML attributes from dynamic content?

I have made a simple blog using Node/Express/Mongo/Jade (and/or HAML.js). I used (and slightly updated) the blog app from this tutorial, which itself an update of one from howtonode.org
I can render attributes such as links, etc., with the template engine just fine, but when I pass data from the db, none of the html renders. I get plain text print-outs of the HTML. I figure I need some other node packages/modules to render the 'dynamic' content, but I don't know where to start.
In jade, when you're passing content you DON'T want to be escaped, be sure you pass it along as != instead of =
BE EXTREMELY CAREFUL THOUGH! If you don't manually parse out the bad stuff, you could make your website extremely vulnerable.
You can read some more jade documentation here