2

How to combine css/js in laravel

if I have this:

<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="css/styleol.css" type="text/css">
<link href="css/cupertino/jquery-ui-1.10.3.custom.css" rel="stylesheet">

how can I make less HTTP request for example,

<link rel="stylesheet" href="css/style.css;css/styleol.css;css/cupertino/jquery-ui-1.10.3.custom.css" type="text/css">
2
  • You need to use a bundling/minification tool like bundles.laravel.com/bundle/Laravel-JS-CSS-Minifier-Combiner Have you already tried any tools or do you want to know how to use the bundling tool? Commented Jun 25, 2014 at 16:07
  • Your best solution is to precompile all CSS together. You can use front-end tools like Grunt to assist you. Commented Jun 25, 2014 at 22:40

3 Answers 3

2

try to use this package, your can call it in your view like this

// minify and combine all stylesheet files in given folder
{{ Minify::stylesheetDir('/css/') }}

https://github.com/ceesvanegmond/minify

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use CodeSleeve/asset-pipeline, this will automatically combine all of your assets (css/js) into a single file and also minify the code into one single file. This means that, the browser will make only one request, and the size of the file could be be greatly reduced.

Read the documentation on Github page and install it using Composer.

1 Comment

Authors claim they will not develop this further since L5 includes a method to do it.
1

You can use Laravel Elixir to combine and minify all your project's CSS file in a single file and you can use the same for your js files. Read this tutorial http://www.techigniter.in/tutorials/minify-and-combine-css-and-js-using-laravel-elixir/

1 Comment

This is the official way for L5 but I dislike having to install nodejs just to do this :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.