I am using the Grape framework to retrieve data, which is working great. I would also like to retrieve a JavaScript file using the API. For example:
<!DOCTYPE html>
<html>
<head>
<script defer src="http://someapi.com/dni_js/dni.js" > </script>
</head>
<body>
</body>
</html>
http://someapi.com/dni_js/dni.js is calling the API.
What would be the best way to accomplish this?
You should implement support for JSONP in your API.
https://github.com/intridea/grape#jsonp
Related
I've been trying to understand how can I use Angular 5 (or 2 or 4) together with Spring thymeleaf template together. My problem is that Angular 5 runs on CLI and it resolves as it's own project (app folder). But that makes it SPA and to be honest I do not like full SPA applications. In my opinion it makes them slow when huge data is there to be processed.
Instead I want to make multi page applications (which means page refresh and server side rendering). And I want to use some Angular 5 features (for example two way data binding). But how exactly I can achieve that? In Angular 1 (AngularJS) all I had to do was include it's source and done. But how about with Angular 5?
Its not much different from AngularJS. You just need to include compilation of the typescript to javascript in your build using something like frontend-maven-plugin. In your thymeleaf templates you would need to point to your generated js files.
Check out the following:
http://justincalleja.com/2016/04/17/serving-a-webpack-bundle-in-spring-boot/
http://blog.gerardin.info/archives/824
I used Thymeleaf to serve a common header and footer
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My APP</title>
</head>
<body>
<header th:replace="header.html :: headerContent">header content</header>
<app-root></app-root>
<footer th:replace="footer.html :: footerContent">footer content</footer>
<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
const jsonPromise = fetch("https://www.google.com");
jsonPromise.then(() => alert("done"));
</script>
</head>
<body>
</body>
</html>
This is my HTML. The graph shows the HTML download finished early but the ajax is sent at 181ms.
I believe Chrome doesn't need 180ms to parse the simple HTML. What is it doing in the interim? Can Chrome send the request as soon as possible?
In my real application, I request JSON from my server. The JSON is the critical data for rendering the page, otherwise the page is blank. That's why I want the browser to send the request as early as possible.
The same happens for Firefox
I got it. I have too many extensions. Once I disable all extensions, the ajax is sent at 8ms.
I consider moving from Thymeleaf templating to EJS templating in my Spring Boot application (there is a need to execute some javascript code on server side). I've successfully configured everything and created my first view using few online examples:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Hello</title>
</head>
<body>
Hello <%= username %>
</body>
</html>
This works OK when I pass String variable named "username" from controller to view. However, I would like my view to use messages from static file "/resources/i18n/messages.properties". In thymeleaf it is widely used, simple and possible by:
th:text="#{messages.hellomessage}"
How to achieve the same result using EJS?
You'll have to create a new ScriptTemplateViewResolver and also create a new ScriptTemplateConfigurer leveraging the Nashorn support as engine.
Take a look at this tutorial for an example.
I am trying to implement a signup PopUp from Mailchimp but as it seems, I am not able to make it working! Here's the code:
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="http://s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"http://mc.us9.list-manage.com","uuid":"146962178e8704d5ccaf9c28f","lid":"e13cc10d95"}) }) </script>
</head>
<body>
<p>This is a test!</p>
</body>
</html>
If I open the html file (locally), it loads but nothing else happen. Also there is no html code embedded what I would expect it to do. Do you have any ideas?
you have to know a couple of things:
this shows your popup on page load (hence no HTML code)
it only shows once since it places a cookie, and if you already saw your popup won't bother you with it again. (try it in private mode in your browser)
Try to add in header this google libraly <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
i'm trying to create dynamic PDF's using ABCPdf and i'm having no success. I copied their sample code and tried it and i receive an error:
Unable to render HTML. No MSHTML document is available.
I'm trying to figure out how to use the Gecko engine to reder the page instead of IE and can't find how. Any help is greatly appreciated... thanks all!!!
damien
Please see https://stackoverflow.com/a/11504285/1411950. This example uses the 1 rectangle for html->pdf output on each page. The rectangle is filled with raw html / html from url. It also can use Gecko engine.
If you want to make dynamic pdf, you should use raw html for its content. Note, that it should be wrapped into something like
const String HtmlWrapper = #"<!DOCTYPE html>
<html>
<head profile='http://www.w3.org/2005/10/profile'><title></title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<style type='text/css'>
</style>
</head>
<body>
{0}
</body>
</html>";
where all css goes in script tags in the header or is referenced to