Ellatronic
Design Portfolio

Blog

Posts tagged git
This Week I Learned | Git Basics II, Github, Front End Optimization

Git Basics Part II

Cloning

  • The first step is cloning a repository to your computer
    • remote repository - a repo on another computer with access to it over a network
    • Remote can simply mean somewhere else

git clone ~/[name] [name_of_new_clone]

  • Cloning creates a copy of the repo without changing it in any way
  • Set up remotes to talk to each other by using:

git remote add our_clone ~/our_clone_project/

Pushing and Pulling

git pull origin new_feature

  • origin is the remote to pull from
  • new_feature is what branch we want to get the history from

git push our_clone

  • By default, Git asssumes pushing and pulling from the origin remote
    • Just use git push for default behavior
  • Since we are not pushing to the default, we must specify our clone

Github

  • pull request - what you do when you have code you want someone to pull into their project

Front End Optimization

  • Modification of HTML, CSS, JS, and sometimes server configuration for the purpose of improving page load times
  • performance budget - quantifiable target for how fast a website loads
    * Can be in the form of total HTTP requests, page weight, total response time, or any combination of these
    • page weight - total file size of all a site's assets

HTTP Requests

  • Pay attention to total number of HTTP requests on a web page
  • Even when no data is sent, like a 404 error, an HTTP request will still take up time
  • Each HTTP request is generally fast, but lots of little assets, including small ones like icons, can add up
  • sprite map - take small images like icons and put them together into one big image, then split it apart using HTML and CSS
    • Since a sprite map combines many small images into one big image, the result is one HTTP request instead of many
  • 404 errors indicate the server could not find the requested asset and are often caused by typos or file manipulations (files moved or deleted)

Optimize Images

  • Images use the most bandwidth
  • Use SVGs first - they are small in file size by covering large areas of the screen using just a few vector points rather than thousands or millions of individual pixels like JPEG or PNG
  • Resize/compress images
  • Using hosted services for assets like fonts is better for speed and reliability, additional parallel HTTP connections, and better caching
  • If possible, put JS on the bottom of the HTML page to make the page appear to load faster even though it might actually load in the same amount of time

Minify Assets

  • CSS and JS are often filled with spaces, line breaks, comments, and long variable names. A web browser does not need these to parse properly but they are still downloaded when a site visitor loads the page.
  • Minifying assets removes these extra bits and reduces overall page weight
This Week I Learned | Git Basics and JavaScript Basics

Git Basics

  • VCS - version control system
    • allows developers and designers to all work on the same code base
  • running git init without a name will create a repository in the folder you are currently working in
  • everything important about the repository is stored in the .git folder, so you can rename the folder holding your project files without causing any problems


git commit -a -m "message here"

-a adds all files. -m is the message flag.

The Staging Area

  • git status - shows us the current version control status of our project
  • git log to see past commits
  • check a version out using git checkout and the first 5-6 characters of the commit hash
    • get two commits and browse the differences between them

Branching Out

  • master is the default branch of any git repository
    • often thought of as the trunk
    • the version of code typically deployed in production
  • git branch [name] to create a new branch, use short and meaningful names
  • git checkout to switch branches
  • git checkout -b [name] to create and switch to a new branch
    • creating a new branch makes a copy of the branch you are currently in and uses it as a base for the new branch
  • git branch -D [name] to delete a branch

Merging

  • merging brings your branches back to master
  • makes a cohesive timeline of commits
  • merge conflict - happens when the same files have been changed in different branches
    • resolve the conflict by deciding which changes are most important to keep
  • in most cases, Git can and will automatically resolve merge conflicts for you
  • git checkout master to switch to master, then git marge [name_of_branch_to_merge]

Resolving Merge Conflicts

  • when automatic merging fails, you will need to resolve conflicts manually by
    • remove conflict markers to keep both sets of changes
    • delete one change
    • combine both changes
  • then git add [file] and git commit -m "message"

JavaScript Basics

  • string values are immutable - they cannot by altered once created. This means the individual characters of a string literal cannot be changed.

Cannot do:

var myStr = "Bob";
    myStr[0] = "J"; // -> "Job"

Can do:

var myStr = "Bob";
    myStr = "Job";

Can only change a string by completely replacing it.

  • if you assign a value to a variable that has not been declared (no var keyword), it will automatically become a global variable.
  • the lifetime of JavaScript variables begins when they are declared
    • local variables are deleted when the function is completed
    • global variables are deleted when you close the page

Global vs Local Scope in Functions

  • when both local and global variables have the same name, the local variable takes precedence
  • queue - an abstract data structure where items are kept in order
    • new items are added to the back of the queue
    • old items are taken off the front of the queue