Hi guys..
I have big problem about caching js or css files.
which should i use, using http header or just direct to js or css files.
for example, i have controllers to load one or multiple js files and caching using http headers:
and in my view files:
or like this:
please some one to teach me..
I have big problem about caching js or css files.
which should i use, using http header or just direct to js or css files.
for example, i have controllers to load one or multiple js files and caching using http headers:
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class asset_feed extends CI_Controller
{
public function script()
{
if (ENVIROTMENT === 'development') {
session_write_close();
}
$this->output->set_header('Content-Type: text/javascript; charset=UTF-8');
$this->output->set_header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
if (! empty($_GET['scripts']) && is_array($_GET['scripts'])) {
$data = '';
foreach ($_GET['scripts'] as $script) {
$script_name = 'assets/js';
$path = explode("/", $script);
foreach ($path as $index => $filename)
if (preg_match("@^[\w][\w\.-]+$@", $filename))
$script_name .= DIRECTORY_SEPARATOR . $filename;
if (preg_match("@\.js$@", $script_name) && is_readable($script_name)) {
$data .= read_file($script_name);
$data .= ";\n\n";
}
}
$this->output->append_output($data);
}
}
}
and in my view files:
Code:
<script type="text/javascript" src="http://localhost:8000/asset_feed/script?scripts[]=file1.js&scripts[]=file2.js"></script>
or like this:
Code:
<script type="text/javascript" src="http://localhost:8000/assets/js/file1.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/js/file2.js"></script>
please some one to teach me..