⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Suggestion for minor enhancement



ezgoen

ezgoen
  • profile picture
  • Member

Posted 04 April 2013 - 01:01 AM

 

Hi

 

Firstly - thanks again for grocerycrud

 

I have a minor suggestion 

I really like the notion of NOT including the same css and the same js multiple times

It's a good enhancement for faster load times

 

I would like to be able to use the gc set functions from my controller - so as to ensure

I don't add duplicate scripts

 

In order to also facilitate the adding of scripts outside the GC directory tree

I would like to suggest the following code :

        //for backward compatibility
	public function set_css($css_file)
	{
		$this->add_include($css_file);
	}

	//for backward compatibility
	public function set_js($js_file)
	{
		$this->add_include($js_file);
	}
	
	public function add_include($inc_file){
		$fn = (strpos($inc_file,"/") === 0 ) ?  substr($inc_file, 1)  : $inc_file;
		if (strripos($fn,'.js',-3) !== False)  {  
			if (! file_exists("$fn")){
				$fn = $this->default_javascript_path."/$fn" ;
			}
			if(file_exists("$fn")){
				$this->js_files[sha1($fn)] = base_url().$fn;
			} else {
				throw new Exception("Missing JavaScript (.js) file. Tried : $inc_file and $fn");
			}
		} elseif (strripos($inc_file,'.css',-4) !== False) { 
			if (! file_exists("$fn")){
				$fn = $this->default_css_path."/$fn" ;
			}
			if(file_exists("$fn")){
				$this->css_files[sha1($fn)] = base_url().$fn;
			} else {
				throw new Exception("Missing Stylesheet (.css) file. Tried: $inc_file and $fn");
			}
		} else {
			throw new Exception("Request to include unknown file type: $inc_file");
		}
	}

 

 

 

I'm also not entirely sure that a more correct algorithm would be :

sha1(basename($fn))

 

so we get a copy of the file included - but perhaps this may cause problems when relying on different versions of the same file - if they were-named to include their version numbers it would be fine.

 

 

What does da boss think ??

 

 

 

Cheers

 

Ez


davidoster

davidoster
  • profile picture
  • Member

Posted 05 April 2013 - 16:20 PM

Interesting view point!

Though, be a little more patience.

When the new new new version comes out it will include support of different frameworks, not just CI.

There issues, like using GC outside the directory tree, obviously will be addressed!

 

Very good point though!