How Load asset only once laravel 5.3? - laravel

How Load asset only once. if i open dashboard, all asset will be load and then i open other page, not load asset second time..
how to make load asset only once in blade template?
ex:
template.blade.php
#yield('css')
#yield('js')
dashboard.blade.php
#section('css')
//some code here
#endsection
group.blade.php
#section('css')
//some code here
#endsection
any help me?
thanks

That's not how the HTTP protocol works. The HTTP protocol is stateless, meaning it does not remember that a user visited the dashboard before they visited group.
The only assurance you have is that when a user visits the dashboard the CSS of the dashboard will be cached so subsequent requests for them will load them from the cache and not from the webserver.
However you must assume that a user could visit group first so all required CSS for group must be included in the group template, even if that means that means you'll be replicating some CSS for each page.
If you really want to load each asset only once then you should use a JavaScript library like jquery mobile to specify different sections that are loaded via AJAX. However the how and why is way too broad a question to cover here.

Why you loading asset with #yield? Just load it on your layouts.
For example app.blade.php which in layouts folder.
app.blade.php
<html>
<head>
<link rel="stylesheets" href="{{asset('css/style.css')}}"/>
<title>title goes here</title>
</head>
<body>
#yield('content')
<script src="{{asset('js/jquery.js')}}"></script>
</body>
</html>
Then load layout on any view for example dashboard
dashboard.blade.php
#extends('layouts.app) //it loads all template data from layouts(app.blade.php)
#section('content')
content for dashboard
#endsection

Related

CSS files not being used when fetched via localhost as resource

I have a local server running on Tomcat.
There is currently a single landing page, which is some HTML with a simple CSS style.
My problem is, when I try to send the CSS file as a resource from my JAX-RS server, it shows up in the browser, however, it is not used by the browser to style the HTML.
Here is how it looks:
As you can see, the CSS is there, it's really simple, but it doesn't change the background.
Now, I tried to do the simplest version possible, where I just put the HTML and CSS in the same folder, and exclude the localhost request, just link it together, and it worked.
I send script files via this function:
#GET
#Path("/{scriptName}")
#Produces(MediaType.TEXT_HTML)
public InputStream getScript(#PathParam("scriptName") String scriptName) {
return ScriptService.getScript(scriptName);
}
In my HTML, the way I put it together in the <head> part is this:
<head>
<title>Home</title>
<link rel="stylesheet" href="http://localhost:8080/WebProject/scripts/mycss.css" type="text/css">
</head>
<body>
<div class="hello">
This is some text
</div>
<div class="hello2">
It is nice to meet you sir.
</div>
</body>
Do you guys have any idea on why this is happening?
Btw, as a side note, I use the same code to fetch my Vue.js scripts, and they work perfectly fine.

Highlight.js not workng on Laravel 5.3 Target Page

I am developing a Blog with Laravel 5.3. In the Add Post Page, I use CKEDITOR with Code Snippet Plugin. In this area Everything is OK. Code added in the textarea field by plugin is also become highlighted.
In the Target Page I added:
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css">
In the Header section of the page.
and
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
In the footer section of the page.
The page received the following html code from the Database.
<p>The place for Laravel Blade Template.</p>
<pre>
<code class="language-html"><div><h1>
This is a Header</h1></div></code></pre>
<p> </p>
which is showing like this.
<p>The place for Laravel Blade Template.</p> <pre>
<code class="language-html"><div><h1>This is a Header</h1></div></code>
</pre> <p> </p>
So the code section is not highlighted.
How can I do that. What's my wrong? I need Help.
The problem is, that the whole HTML code is escaped, so it won't be interpreted by the browser.
What you want is that only the content between <code class="language-html">...</code> is escaped, so that the Browser renders the code container correctly and that highlight.js can hook into the DOM object.
In Laravel 5 to output non escaped HTML you must use {!! !!}
An example of this:
{!!$myDatabaseHtml!!}

CKEditor editable content in IFrame

Is it possible to run ckeditor on an IFrame so that can encapsulate a full html page? I have tried various methods but nothing seems to work.
What I am looking for is to have a ckeditor wrapper page say Editor.htm which contains an editable IFrame linked to my real html page say test.htm. Something line:
Editor.htm
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.ckeditor.com/4.5.10/standard-all/ckeditor.js"></script>
</head>
<body>
<iframe contenteditable="true" src="test.htm" id="editor1" name="editor1"></iframe>
</body>
</html>
You can set ckeditor to use "fullPage" mode, allowing you to edit everything from the opening tag to the closing tag. See the official sample here.
You will still need to get the content into the editor (e.g. the html page you want to edit) and save the result on the server, but this is something specific to your site, language, platform etc.

How not to be confined into content area... full size web app on Joomla

I am currently creating an Intranet ERP application that will integrate an already existing corporate Joomla 3.1 based web site.
The extension i made so far only has one default controller php file and everything is made using a JavaScript UI framework. (i.e. jqWidgets) So i am not using model, views, helpers.
The other php files are there to respond to the client side interface AJAX requests.
So i mainly need Joomla for the user authentication and session control features but i dont want it to confine my extensions output to the content area... i need the entire document surface... no menu, no module columns, no nothing !
Can it be done ?
Two ways
component.php in the template will show only the component's output add &tmpl=component to your urls
Make a custom template that only outputs the component
<html>
<head>
<!-- put what scripts stylesheets you need etc//-->
</head>
<body>
<jdoc:include type="component" />
</body>
</html>

Facebook button for Ajax Pages, how to implement and verify that it works

I wanted to know how can I use Facebook Like button on my Ajax web application, that will capture changes in the Open Graph tags for both the og:title and the og:url. I already created a Facebook app and got an API ID.
What I want to know is the code that I need to put on my website in order for Facebook to capture the changes that I've made to the meta tags which contains that title and url information (ie. og:title, og:url).
I followed the instructions on Facebook without success. Furthermore, I want to know how can I locally test the Like button to see that it grabs the data from the Open Graph tags properly.
Also worth mentioning that I've a JQuery code that automatically alters the Open Graph meta tags to include the relevant information for the current Ajax changed page.
Thanks.
You will need to have a separate url for each different page that you want to allow people to like. I would recommend actually pointing the like button to the physical pages you're trying to return via the og:url tag. To refresh the data that Facebook stores about a given url, pass that url into the linter at http://developers.facebook.com/tools/lint.
i created a rotator file for facebook share on my dynamic ajax website.
rotator.asp code sample:
<html>
<% lang=request("lang")
id=request("id")
..some sql to get data...
ogTitle=....
ogImage=....
originalUrl=....
%>
<head>
<meta property="og:title" content="<%=ogTitle%>" />
<meta property="og:image" content="<%=ogImage%>" />
.....
......
<meta http-equiv="refresh" content="0; url=<%=origialUrl%>" />
//dont use redirect.. facebook dont allow 302...
</head>
<body></body>
</html>
for example xxx.com/#!/en/153 page will share xxx.com/rotator.asp?lang=en&id=153

Resources